This library provides functions to merge JSON documents in accordance with RFC 7386, the JSON Merge Patch standard. It offers a simpler alternative to JSON Patch for updating JSON resources, especially for object-based modifications. The current version is 0.3.0, with a focus on implementing the standard without external dependencies beyond the standard library.
pip install json-merge-patchVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to apply a JSON merge patch to a document and how to generate a patch document by comparing an original and a target document. Note that the library expects and returns Python dictionaries; JSON serialization/deserialization is the user's responsibility.
If granular array operations are needed, consider using JSON Patch (RFC 6902) instead, which provides 'add', 'remove', and 'replace' operations for array elements.
Ensure that `null` values in your patch explicitly mean deletion. If you need to set a value to `null`, JSON Merge Patch is not the appropriate mechanism, and you should use JSON Patch (RFC 6902) or a full document replacement.
Always parse incoming JSON strings into Python dictionaries using `json.loads()` before passing them to `json_merge_patch` functions, and convert the resulting dictionaries back to JSON strings using `json.dumps()` if needed for output or storage.
Upgrade your Python environment to 3.9 or newer before updating to `json-merge-patch` version 0.3.0 or later.
Use `collections.OrderedDict` for your input documents if key order is a requirement for your merge operation.
Ensure the correct library is installed via `pip install json-merge-patch` and imported using `import json_merge_patch` or `from json_merge_patch import merge`.
Ensure that the arguments passed to `json_merge_patch.merge()` or `json_merge_patch.create_patch()` are valid Python dictionaries. If your JSON data is in string format, use `json.loads()` to parse it into a dictionary first.
Before passing JSON data to `json_merge_patch` functions, validate the JSON string to ensure it is well-formed. Use a JSON linter or validator, or carefully check for common syntax errors. Ensure that `json.loads()` successfully converts the string into a Python dictionary.
No dependency data recorded yet.