JSON Diff
Compare two JSON objects and visualize differences. Outputs RFC 6902 JSON Patch operations and a color-coded tree diff. Runs in your browser.
- Runs in your browser
- Tool input is not uploaded to ZeroTool servers
- Free · No Sign-Up
Scan with WeChat to share this tool
Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.
Use Cases
- Review API response changes between versions.
- Generate patch operations for PATCH HTTP endpoints.
- Audit configuration file changes.
- Debug unexpected data mutations in your application.
Related tool: JSON Formatter — prettify and validate JSON before diffing.
Example: An API Response Changes
Before:
{"name":"Alice","status":"pending","legacy_id":12345,"tags":["a","b","c"],"profile":{"age":30,"city":"Paris"}}
After (keys reordered, status changed, legacy_id removed, role added, first tag dropped):
{"status":"active","name":"Alice","role":"admin","tags":["b","c"],"profile":{"age":31,"city":"Paris"}}
Visual Diff:
~status: "pending" → "active"
−legacy_id: 12345
~tags.0: "a" → "b"
~tags.1: "b" → "c"
−tags.2: "c"
~profile.age: 30 → 31
+role: "admin"
JSON Patch:
[
{ "op": "replace", "path": "/status", "value": "active" },
{ "op": "remove", "path": "/legacy_id" },
{ "op": "replace", "path": "/tags/0", "value": "b" },
{ "op": "replace", "path": "/tags/1", "value": "c" },
{ "op": "remove", "path": "/tags/2" },
{ "op": "replace", "path": "/profile/age", "value": 31 },
{ "op": "add", "path": "/role", "value": "admin" }
]
Key order does not matter: name moved but is not reported, because a JSON object is an unordered collection of members (RFC 8259, section 4). The operations run from top to bottom, and each one sees the document as the previous one left it (RFC 6902, section 3). The patch applies with Python's jsonpatch 1.33 and gives the After document:
import jsonpatch # pip install jsonpatch
before = {"name": "Alice", "status": "pending", "legacy_id": 12345,
"tags": ["a", "b", "c"], "profile": {"age": 30, "city": "Paris"}}
patch = jsonpatch.JsonPatch([...]) # paste the patch from the tool
after = patch.apply(before)
Example: Several Items Removed From a List
An order that had three line items now has one, and its quantity changed:
[
{ "op": "replace", "path": "/items/0/qty", "value": 3 },
{ "op": "remove", "path": "/items/2" },
{ "op": "remove", "path": "/items/1" }
]
The removals are written from the highest index down. After remove /items/2 the array has two elements, so /items/1 still exists. In the other order, the second removal would point past the end of the array; when an operation fails, the whole patch fails (RFC 6902, section 5).
How Arrays Are Compared
Arrays are compared by index, not by content. Dropping the first tag from ["a","b","c"] shows up as two replacements and one removal instead of a single remove /tags/0. The patch is correct; it is longer than necessary. Elements past the end of the shorter array become remove operations (highest index first) or add operations (lowest index first).
Paths and JSON Pointer Escaping
Patch paths are JSON Pointers (RFC 6901): ~ is written ~0 and / is written ~1. The whole document is the empty path ""; / would point to a member whose name is the empty string. For {"a/b":1,"m~n":2,"list":[1,2,3]} → {"a/b":2,"list":[1,2,3,4],"x":null} the tool gives:
[
{ "op": "replace", "path": "/a~1b", "value": 2 },
{ "op": "remove", "path": "/m~0n" },
{ "op": "add", "path": "/list/3", "value": 4 },
{ "op": "add", "path": "/x", "value": null }
]
When the two roots have different types, such as an object and an array, the patch replaces the whole document:
[
{ "op": "replace", "path": "", "value": [1] }
]
The Visual Diff joins keys with dots (profile.age, list.3) for reading only; use the paths from the JSON Patch in code.
Numbers JavaScript Cannot Hold
JSON allows any number of digits, but JavaScript reads every number as a 64-bit float, and RFC 8259 notes that only integers in the range [-(2^53)+1, (2^53)-1] are interoperable (RFC 8259, section 6). Here both IDs are past that range:
[
{ "op": "replace", "path": "/id", "value": 9007199254740996 },
{ "op": "replace", "path": "/status", "value": "paid" }
]
The status line names both numbers:
2 change(s) detected. JavaScript cannot hold these numbers exactly and compares them as rounded values, so differences in them can be missed and the patch writes the rounded values: Before /id: 9007199254740993 → 9007199254740992; After /id: 9007199254740995 → 9007199254740996.
The patch sets /id to 9007199254740996, not the 9007199254740995 in the After text. If IDs like these must survive, send them as strings. The same scan names keys that appear twice in one object, because JSON.parse keeps only the last value.
How the Patches Are Checked
The tool's test suite applies every generated patch to Before and compares the result with After, using a strict RFC 6902 implementation and, when it is installed, Python's jsonpatch. Besides the examples on this page, it runs 3,000 random document pairs with nested arrays and keys such as constructor, __proto__, "", a/b, and m~n.
Limits
- No
moveorcopyoperations are generated; a renamed key appears asremoveplusadd. - Arrays of objects are not matched by an
idfield, and an element inserted at the start of an array makes every later element look changed. - Numbers are compared after JavaScript parses them, so
1.0and1are equal, and-0is written as0in the patch. Integers beyond 2^53 that a double cannot hold exactly (9007199254740993;9007199254740994and1e20are exact) and very long decimals are rounded, and numbers too large for a double, such as1e400, become Infinity. The status line names them (first 10, then a count of the rest), and the patch writes the values as read (1e400becomesnull). - A key that appears twice in one object keeps only its last value; the status line names it.
- A document nested about 1,900 levels deep (Node.js 22; the depth depends on the browser) cannot be compared. The status line says so.
- Both inputs must be valid JSON. The status line names the side that failed, for example
Before JSON parse error: Expected double-quoted property name in JSON at position 7.
FAQ
What is RFC 6902 JSON Patch?
RFC 6902 defines a JSON document format for expressing a sequence of operations to apply to a JSON document. Each operation is an object with 'op' (add/remove/replace/move/copy/test), 'path' (JSON Pointer per RFC 6901), and optionally 'value'. This tool writes only add, remove and replace operations.
How does the visual diff work?
The tool performs a deep recursive comparison. Keys present only in 'After' are shown as additions (+). Keys present only in 'Before' are shown as removals (−). Keys with changed values are shown as changes (~) with both the old and new values. Paths in the visual diff are joined with dots for reading; use the JSON Pointer paths from the patch in code.
Why does it say 'No differences' when two IDs differ?
JavaScript reads JSON numbers as 64-bit floating-point values, so integers beyond 2^53 that a double cannot hold exactly, and very long decimals, are rounded, and 1830000000000000001 and 1830000000000000002 both become 1830000000000000000. The tool compares the values as read, but it scans both inputs and lists in the status line the rounded numbers and the keys that appear twice in one object, with their JSON Pointer paths (the first 10 of each, then a count of the rest).
Can I compare large JSON files?
There is no size limit; the comparison runs only when you click Compare, in the browser tab. Very deep nesting is the practical limit: a document nested about 1,900 levels deep (measured in Node.js 22; browsers differ) runs out of the call stack, and the status line reports that nothing was compared.
How is this different from the Diff Checker tool?
The Diff Checker tool compares plain text line-by-line. This JSON Diff tool understands JSON structure — it compares values semantically, not textually, and outputs machine-readable JSON Patch operations.
Is my JSON data sent to any server?
No. Both documents are compared in this browser tab; they are not sent anywhere and are not saved in browser storage. When a comparison of a new pair of inputs finds differences, the page's analytics records one usage event (the tool name and the action diff), without the JSON or the patch.