Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions jsonpath_ng/ext/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,11 @@ def find(self, datum):
found = []
for data in datum:
value = data.value
if isinstance(self.value, int):
if type(self.value) is int:
try:
value = int(value)
except ValueError:
continue
elif isinstance(self.value, bool):
try:
value = bool(value)
except ValueError:
continue

if OPERATOR_MAP[self.op](value, self.value):
found.append(data)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_jsonpath_rw_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@
["green"],
id="boolean-filter-string-true-string-literal",
),
pytest.param(
"foo[?flag = true].color",
{
"foo": [
{"color": "blue", "flag": True},
{"color": "green", "flag": 2},
{"color": "red", "flag": "hi"},
{"color": "gray", "flag": None},
]
},
["blue"],
id="boolean-filter-with-null",
),
)


Expand Down