JSON Semantic Diff & RFC 6902 Patch

Semantic JSON comparison that ignores whitespace and key order. Pinpoints added, removed, and modified values, and generates standard RFC 6902 JSON Patches.

Embed this tool on your website / blog No code required · Copy and paste
HTML Embed Code (iframe):
<iframe src="https://lucentool.com/json-diff" width="100%" height="650" style="border:1px solid #e5e0d8;border-radius:12px;max-width:850px;width:100%;" frameborder="0"></iframe>
<div style="font-size:12px;color:#78716c;margin-top:6px;font-family:sans-serif;">Powered by <a href="https://lucentool.com/json-diff" target="_blank" style="color:#c85a32;text-decoration:none;">Lucentool - JSON Semantic Diff & RFC 6902 Patch</a></div>

Why Line-by-Line JSON Diffing Fails

RFC 8259 defines JSON objects as unordered collections of zero or more name/value pairs. Standard text-line diffing treats key order differences and indentation whitespace as destructive changes, producing massive false-positive churn.

Understanding RFC 6902 JSON Patch

RFC 6902 defines a JSON document structure for expressing a sequence of operations to apply to a target JSON document. Commonly used in HTTP PATCH methods and Kubernetes resource updates.

Edge cases and hard limits

runDiff() parses both documents and walk() compares them key by key, collecting added, removed and changed paths. The comparison stops descending when the shapes disagree — a value that changes type, either side being null, or one side being an array while the other is an object — and records a single replace operation at that path instead of a cascade of nested changes. generateJsonPatch() then emits the collected operations as an RFC 6902 patch array, each carrying oldValue next to value so the change can be reasoned about or reversed.

Formats, sizes and other limits

Arrays are compared by index, which is the sharp edge: inserting one element at the front shifts everything after it, so a one-item addition is reported as a change to every following element. Cyclic structures are not supported and will recurse until the browser stops you. Very large documents can exhaust the call stack, and patch order follows object iteration, so it may not match the order in which you wrote the keys.

Privacy: processed in your browser

Both documents are parsed with JSON.parse inside the page and compared in memory; no diff, no key name and no value is transmitted or persisted.

Frequently asked questions

Why did adding one array item mark everything as changed?

Because comparison is positional. Use an object keyed by id when stable diffing matters, or read the patch as a set of shifts rather than edits.

Can I export a patch?

Yes — the output is an RFC 6902 patch array, which is what libraries like fast-json-patch consume. It is not a merge patch (RFC 7386), so the two are not interchangeable.

Does it handle large files?

It handles what the browser can parse and the stack can recurse through. Beyond a few megabytes, diff in slices or on the server.