From d0bd3516cf4292468828c196271dc6e828179faf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Jun 2026 06:41:05 +0000 Subject: [PATCH 1/2] Initial plan From f935d9538edf18d51d286268488630bdbce6344f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Jun 2026 06:43:19 +0000 Subject: [PATCH 2/2] Fix _compare_lists to use dumps() comparison instead of == to distinguish 1 from True --- jsonpatch.py | 13 ++++++++----- tests.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/jsonpatch.py b/jsonpatch.py index d3fc26d..25d11a4 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -880,17 +880,20 @@ def _compare_lists(self, path, src, dst): for key in range(max_len): if key < min_len: old, new = src[key], dst[key] - if old == new: - continue - - elif isinstance(old, MutableMapping) and \ - isinstance(new, MutableMapping): + if isinstance(old, MutableMapping) and \ + isinstance(new, MutableMapping): self._compare_dicts(_path_join(path, key), old, new) elif isinstance(old, MutableSequence) and \ isinstance(new, MutableSequence): self._compare_lists(_path_join(path, key), old, new) + # To ensure we catch changes to JSON, we can't rely on a + # simple old == new, because it would not recognize the + # difference between 1 and True, among other things. + elif self.dumps(old) == self.dumps(new): + continue + else: self._item_removed(path, key, old) self._item_added(path, key, new) diff --git a/tests.py b/tests.py index d9eea92..c012eff 100755 --- a/tests.py +++ b/tests.py @@ -511,6 +511,16 @@ def test_issue103(self): self.assertEqual(res, dst) self.assertIsInstance(res['A'], float) + def test_issue180(self): + """In JSON 1 is different from True in list items even though in python 1 == True""" + src = {'aaa': [1, 1, 1]} + dst = {'aaa': [1, True, True]} + patch = jsonpatch.make_patch(src, dst) + res = jsonpatch.apply_patch(src, patch) + self.assertEqual(res, dst) + self.assertIsInstance(res['aaa'][1], bool) + self.assertIsInstance(res['aaa'][2], bool) + def test_issue119(self): """Make sure it avoids casting numeric str dict key to int""" src = [