Skip to content
Draft
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
13 changes: 8 additions & 5 deletions jsonpatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down