Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/jsonata/jsonata.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,9 @@ def evaluate_equality_expression(self, lhs: Optional[Any], rhs: Optional[Any], o

result = None
if op == "=":
result = lhs == rhs # isDeepEqual(lhs, rhs);
result = utils.Utils.is_deep_equal(lhs, rhs)
elif op == "!=":
result = lhs != rhs # !isDeepEqual(lhs, rhs);
result = not utils.Utils.is_deep_equal(lhs, rhs)
return result

#
Expand Down
21 changes: 21 additions & 0 deletions src/jsonata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ def create_sequence_from_iter(it: Iterable) -> list:
sequence.sequence = True
return sequence

@staticmethod
def is_deep_equal(lhs: Optional[Any], rhs: Optional[Any]) -> bool:
if isinstance(lhs, list) and isinstance(rhs, list):
if len(lhs) != len(rhs):
return False
for ii, _ in enumerate(lhs):
if not Utils.is_deep_equal(lhs[ii], rhs[ii]):
return False
return True
elif isinstance(lhs, dict) and isinstance(rhs, dict):
if lhs.keys() != rhs.keys():
return False
for key in lhs.keys():
if not Utils.is_deep_equal(lhs[key], rhs[key]):
return False
return True
if lhs == rhs and type(lhs) == type(rhs):
return True

return False

class JList(list):
sequence: bool
outer_wrapper: bool
Expand Down
7 changes: 7 additions & 0 deletions tests/types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def test_ignore(self):
expr2.set_validate_input(False)
with pytest.raises(TypeError):
expr2.evaluate({"a": a_set})

def test_fix_issue_21(self):
"""
https://github.com/rayokota/jsonata-python/issues/21
"""
assert jsonata.Jsonata("true = 1").evaluate({}) is False
assert jsonata.Jsonata("false = 0").evaluate({}) is False
Loading