Registry / serialization / json-delta

json-delta

JSON →
library2.0.2pypypi✓ verified 21d ago

JSON-delta is a multi-language software suite for computing deltas between JSON-serialized data structures and applying those deltas as patches. It aims to minimize communications overhead when manipulating data structures between separate programs. The Python implementation, currently at version 2.0.2, is considered the reference implementation, though it has seen limited development activity since its last release in October 2020.

pip install json-delta
INSTALL
IMPORT
SIG · JSON-DELTA
J
json-delta
serializationpythonv2.0.2
Install
1.6s avg
Import
18ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.020s · 18MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

diff
from json_delta import diff
Imports the function to compute the difference between two JSON structures.
patch
from json_delta import patch
Imports the function to apply a computed diff to a JSON structure.

This quickstart demonstrates how to compute the difference (delta) between two Python dictionaries representing JSON structures and then apply that delta to the original structure to reconstruct the modified one.

from json_delta import diff, patch # Original JSON-like data structure a = { "name": "John Doe", "age": 30, "address": { "street": "123 Main St", "city": "Anytown" }, "hobbies": ["reading", "hiking"] } # Modified JSON-like data structure b = { "name": "Jane Doe", "age": 31, "address": { "street": "456 Oak Ave", "city": "Otherville" }, "hobbies": ["reading", "coding", "swimming"] } # Compute the diff delta = diff(a, b) print(f"Computed Delta: {delta}") # Apply the patch to 'a' to get 'b_reconstructed' b_reconstructed = patch(a, delta) print(f"Reconstructed B: {b_reconstructed}") assert b == b_reconstructed print("Original 'b' and reconstructed 'b' are equal.")
Debug
Known issues
gotchaThe `json-delta` project has shown limited activity since its last release in October 2020. This indicates that it may not be actively maintained, which could lead to unaddressed bugs, security vulnerabilities, or lack of support for newer Python versions or features.
fix
Assess the project's long-term viability for your application. Consider contributing to its maintenance or evaluating alternative, more actively maintained JSON diffing libraries if long-term support is critical.
affects: 2.0.2 and potentially earlier versions still in use.
gotchaThe diff format generated by `json-delta` is a custom sequence of 'stanzas' (e.g., `[[key_path], update_value]`) and is not directly compatible with standard JSON Patch (RFC 6902). Users expecting an RFC 6902 compliant format will need to implement a conversion layer or choose a different library.
fix
Familiarize yourself with the `json-delta` specific diff format as documented. If interoperability with RFC 6902 is required, consider using libraries explicitly designed for JSON Patch.
affects: All versions
gotchaWhen `diff` generates a deletion stanza (i.e., a stanza without an `update` value), the `patch` function cannot reconstruct the original deleted content if it's later needed for 'unpatching' or auditing. This means some diffs are not fully reversible without external knowledge of the deleted data.
fix
If full reversibility (the ability to 'unpatch' to the exact original state) is required, ensure that deleted data is stored or retrieved through other means, or consider a library that explicitly supports reversible diff formats.
affects: All versions
gotchaThe `diff` function's `minimal` and `verbose` parameters are primarily for backward compatibility and can be superseded by more specific parameters like `array_align`, `compare_lengths`, and `common_key_threshold`. Using `minimal` in conjunction with these specific parameters might lead to unexpected behavior or warnings if `verbose` is also enabled.
fix
Prefer using the more specific parameters (`array_align`, `compare_lengths`, `common_key_threshold`) directly to control diff behavior, rather than relying on the `minimal` parameter, especially if fine-grained control is needed.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'json_delta'
The 'json-delta' library is either not installed, or it's installed but the import statement uses a hyphen in the module name (e.g., `import json-delta`) instead of the correct Python module name, which uses an underscore (`json_delta`).
fix
Ensure the package is installed using `pip install json-delta` and then import it in your Python code as `import json_delta`.
AttributeError: 'list' object has no attribute 'get'
This error occurs when you attempt to use a dictionary-specific method like `.get()` on a Python list. This typically happens when the JSON data loaded (either as input to `json-delta` or as an output from it) is a top-level JSON array, but your code incorrectly assumes it's a JSON object (Python dictionary).
fix
Before attempting to access elements, check the type of your JSON data structure using `type()` or `isinstance()`. If it is a list, iterate over it or access elements by their integer index, rather than using dictionary methods.
TypeError: argument of type 'str' is not iterable
The `json_delta.diff()` and `json_delta.patch()` functions expect Python dictionary or list objects as their primary input arguments, not raw JSON strings. Passing a JSON string directly leads to a TypeError when the function attempts to iterate over or process it as a structured object.
fix
Before calling `json_delta.diff()` or `json_delta.patch()`, parse your JSON string into a Python object using `import json; data_object = json.loads(json_string)`. Alternatively, use the convenience functions `json_delta.load_and_diff()` or `json_delta.load_and_patch()`, which handle the JSON parsing internally.
TypeError: Object of type <SomeCustomType> is not JSON serializable
This error occurs when you attempt to serialize a Python object (e.e.g., the output of `json_delta.diff` or `json_delta.patch`) back into a JSON string using `json.dumps()`, but the object contains elements that are not natively JSON serializable by Python's `json` module (such as Python sets, custom class instances, or other non-standard types).
fix
Ensure that all elements within the Python object you are trying to serialize are standard JSON-compatible types (strings, numbers, booleans, None, lists, or dictionaries). If custom types are present, convert them to a serializable format (e.g., a string representation) or provide a custom `default` serializer function to `json.dumps()`.
Upgrade
Version history
2.0.2latest on PyPI · released Oct 18, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources