Add a function for performing a JSON Merge Patch.

Review Request #9262 - Created Oct. 11, 2017 and updated

Christian Hammond
Djblets
release-0.10.x
705c1db...
djblets

This introduces djblets.util.json_utils.json_merge_patch, an
implementation of JSON Merge Patch (RFC 7396), which is used to apply a
set of changes to a JSON-compatible data structure. Merge Patches allow
for adding new values (which may be complex JSON objects) to
dictionaries or arrays, remove keys from dictionaries or arrays, or
replace existing values.

This has additional support for access control around keys, preventing
certain keys from being replaced or added, optionally aborting the
patching process if encountered.

Unit tests pass.

Tested manually with several targets and dictionaries.

Christian Hammond
Review request changed

Change Summary:

  • Added/improved documentation.
  • Used keyword arguments when calling can_write_key_func.

Commit:

-2df5486990a119cf5af496d1172aec8be28f01aa
+705c1db6cf6ec30decb9688ef53fd6ae07117131

Diff:

Revision 2 (+313)

Show changes

Checks run (2 succeeded)

JSHint passed.
flake8 passed.
Loading...