diff --git a/jsonpath_ng/ext/filter.py b/jsonpath_ng/ext/filter.py index e0bd48a..6ec7d1c 100644 --- a/jsonpath_ng/ext/filter.py +++ b/jsonpath_ng/ext/filter.py @@ -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) diff --git a/tests/test_jsonpath_rw_ext.py b/tests/test_jsonpath_rw_ext.py index a14fd72..ca1c3e9 100644 --- a/tests/test_jsonpath_rw_ext.py +++ b/tests/test_jsonpath_rw_ext.py @@ -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", + ), )