JSON-delta

2.0.2 · maintenance · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →