diff --git a/jsonpath_rw/jsonpath.py b/jsonpath_rw/jsonpath.py index c47653e..4dc9bdd 100644 --- a/jsonpath_rw/jsonpath.py +++ b/jsonpath_rw/jsonpath.py @@ -535,6 +535,9 @@ def __init__(self, start=None, end=None, step=None): def find(self, datum): datum = DatumInContext.wrap(datum) + if datum.value is None: + return [] + # Here's the hack. If it is a dictionary or some kind of constant, # put it in a single-element list if (isinstance(datum.value, dict) or isinstance(datum.value, six.integer_types) or isinstance(datum.value, six.string_types)): diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py index 33c0ea6..4912141 100644 --- a/tests/test_jsonpath.py +++ b/tests/test_jsonpath.py @@ -138,7 +138,8 @@ def test_slice_value(self): self.check_cases([('[*]', [1, 2, 3], [1, 2, 3]), ('[*]', xrange(1, 4), [1, 2, 3]), ('[1:]', [1, 2, 3, 4], [2, 3, 4]), - ('[:2]', [1, 2, 3, 4], [1, 2])]) + ('[:2]', [1, 2, 3, 4], [1, 2]), + ('[*]', None, [])]) # Funky slice hacks self.check_cases([