Skip to content

Commit

Permalink
Merge pull request #1 from denisfrm/find-filter-can-handle-none-values
Browse files Browse the repository at this point in the history
Fix bool filter type to handle None values
  • Loading branch information
denisfrm authored Jan 8, 2025
2 parents 1d16980 + 3d33869 commit c5fce86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit c5fce86

Please sign in to comment.