Semantic JSON Diff & Patch Generator

Compare two JSON documents semantically independent of key ordering. Detect added, removed, and modified paths with type-aware analysis and automatically compile RFC 6902 JSON Patch operations. 100% client-side.
Original (Before) JSON
Valid JSON 0 chars
Modified (After) JSON
Valid JSON 0 chars
Comparison Result: +0 Added -0 Removed ~0 Modified Documents are Identical
Path Differences Breakdown 0 differences
Operation JSON Pointer Path Original Value New Value
RFC 6902 JSON Patch Array
[]

The Theory & Mathematics of Semantic JSON Diffing

Standard text diffing tools (such as UNIX diff or Git diff) treat files as linear arrays of text lines using the Myers Longest Common Subsequence (LCS) algorithm. When applied to JSON documents, text-based diffing frequently produces noisy, misleading results:

1. The Recursive Semantic AST Comparison Algorithm

Semantic JSON diffing operates on the deserialized Abstract Syntax Tree (AST):

  1. Primacy of Types: Both values at path $P$ are checked for type identity. If $T(A) \ne T(B)$ (e.g. string "100" vs integer 100), a replace operation is immediately emitted.
  2. Objects ($M$): Key sets $K_A$ and $K_B$ are calculated.
    • Any key in $K_B \setminus K_A$ is an Addition (add).
    • Any key in $K_A \setminus K_B$ is a Removal (remove).
    • Any key in $K_A \cap K_B$ is recursively compared down to leaf nodes.
  3. Arrays ($L$): Compared sequentially by index, or matched by unique identifier properties when performing collection entity diffing.

2. RFC 6902 JSON Patch Specification

Defined by the IETF in RFC 6902, a JSON Patch document is a JSON array of mutation operations used in HTTP PATCH request bodies. Each operation object defines:

Operation (op) JSON Pointer (path) Payload Description
add /users/0 value: {...} Inserts an element into an array or creates a new object property.
remove /settings/theme None Deletes a property from an object or removes an index from an array.
replace /profile/email value: "new@..." Replaces the existing value at the target path.
move /to/path from: "/from/path" Removes a value from a path and inserts it into a new path.
copy /to/path from: "/from/path" Duplicates a value to a new location.
test /version value: 1 Asserts that a path has an exact value before applying mutations.

3. JSON Pointer Syntax (RFC 6901)

Target paths in RFC 6902 utilize RFC 6901 JSON Pointers:

Frequently Asked Questions

What is the difference between RFC 6902 JSON Patch and RFC 7386 Merge Patch?
RFC 6902 is an explicit array of discrete atomic operations (add, remove, replace). RFC 7386 (JSON Merge Patch) is a simplified mirror document where setting a key to null deletes it, but it cannot delete array elements or distinguish between a property set to null versus deleted.
Does this tool ignore differences in object key order?
Yes. By default, "Ignore Key Ordering" is enabled. Objects with identical properties in different orders are evaluated as 100% identical.
Can I use the generated patch with libraries like jsonpatch in Node.js or Python?
Yes. The generated patch strictly complies with RFC 6902 and can be applied directly using fast-json-patch (Node.js) or jsonpatch (Python).
Copied to clipboard!

We use cookies to enhance your experience. Optional cookies only run if you consent. See our Privacy Policy.