Add a function for performing a JSON Patch.

Review Request #9264 - Created Oct. 12, 2017 and updated

Christian Hammond

This introduces djblets.util.json_utils.json_patch, an implementation
of JSON Patch (RFC 6902). This is another, more advanced method of
patching JSON-serializable data, sort of like with JSON Merge Patch but
with the ability to order operations, copy or move data, sanity-check
values before applying a patch, set values to null, and manipulate
specific indices of arrays. It's a good substitute for JSON Merge
Patches when more specific modifications and sanity-checking is needed.

JSON Patches consist of a list of operations to perform. These are
add, remove, replace, copy, move, and test. All operations
must pass in order for a patch to apply.

This implementation goes beyond most implementations by providing read
and write access control for keys. This allows callers to prevent
reading certain keys or writing to others, limiting the damage that, for
instance, an API call can do.

More information on JSON Patch can be found at or

Unit tests pass.

  • 0
  • 0
  • 2
  • 0
  • 2
Description From Last Updated
Christian Hammond
Review request changed

Change Summary:

  • Improved documentation.
  • Fixed alignment issues.




Revision 2 (+2690 -2)

Show changes

Checks run (2 succeeded)

JSHint passed.
flake8 passed.