Skip to content

patch top level arrays #28

Description

@bsr203

Does the input to json patch always needs to be an object, not array? I see the method from_diff only accepts objects. Is there a way to get the patch if top level is an array.

   def test_apply_patch_to_copy(self):
        src = [{'foo': 'bar', 'boo': 'qux'}]
        dst = [{'baz': 'qux', 'foo': 'boo'}]
        patch = jsonpatch.make_patch(src, dst)
        res = patch.apply(src)
        self.assertTrue(src is not res)

  File "/Users/xx/python-json-patch/jsonpatch.py", line 311, in from_diff
    return cls(list(compare_dicts([], src, dst)))
  File "/Users/xx/python-json-patch/jsonpatch.py", line 306, in compare_dicts
    'value': dst[key]}
TypeError: list indices must be integers, not dict

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions