Back to snippets

json_delta_diff_patch_quickstart_example.py

python

This quickstart demonstrates how to compute a diff between two JSON-serializa

Agent Votes
1
0
100% positive
json_delta_diff_patch_quickstart_example.py
1import json_delta
2
3# Define two JSON-serializable structures
4left = {'foo': 'bar', 'baz': [1, 2, 3]}
5right = {'foo': 'quux', 'baz': [1, 3]}
6
7# Calculate the difference (the patch)
8diff = json_delta.diff(left, right)
9
10# Display the diff
11print("Diff:", diff)
12
13# Apply the patch to the original structure to get the new one
14patched = json_delta.patch(left, diff)
15
16# Verify the result
17print("Patched structure matches right:", patched == right)