Skip to content

Commit 40cc282

Browse files
chdemkomichaelmior
authored andcommitted
Fix single constant case
1 parent ca251d5 commit 40cc282

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

jsonpath_ng/jsonpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def find(self, datum):
796796
return []
797797
# Here's the hack. If it is a dictionary or some kind of constant,
798798
# put it in a single-element list
799-
if (isinstance(datum.value, dict) or isinstance(datum.value, int) or isinstance(datum.value, str)):
799+
if (isinstance(datum.value, dict) or isinstance(datum.value, (int, float, str, bool))):
800800
return self.find(DatumInContext([datum.value], path=datum.path, context=datum.context))
801801

802802
# Some iterators do not support slicing but we can still

tests/test_jsonpath.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ def test_update(parse: Callable[[str], JSONPath], expression: str, data, update_
227227
# Slices
228228
# ------
229229
#
230+
("[*]", 1, [1], ["[0]"]),
231+
("[*]", 1.2, [1.2], ["[0]"]),
232+
("[*]", True, [True], ["[0]"]),
233+
("[*]", "test", ["test"], ["[0]"]),
230234
("[*]", [1, 2, 3], [1, 2, 3], ["[0]", "[1]", "[2]"]),
231235
("[*]", range(1, 4), [1, 2, 3], ["[0]", "[1]", "[2]"]),
232236
("[1:]", [1, 2, 3, 4], [2, 3, 4], ["[1]", "[2]", "[3]"]),

0 commit comments

Comments
 (0)