⚖️ JSON Comparator

JSON Diff & Structure Comparison Tool

Compare two JSON payloads to list added, removed, or modified values at any depth, including nested keys and array items.

Original JSON (A)
New JSON (B)
Difference Output
~ Modified: version changed from "1.0" to "2.0"
+ Added: newFeature: true

Structural comparison versus a text diff

A line-based diff, like the one git shows, compares text. Reformatting a JSON file, changing indentation or reordering keys produces a wall of changes even when the data is identical. A structural diff parses both sides first and compares the resulting values, so formatting noise disappears and only real data changes remain.

This tool walks both documents recursively. Object keys are matched by name, so key order never matters, and arrays are compared position by position. Every difference is reported with its full path, such as settings.theme.color or items[2].price, and classified as added, removed or modified. Values at the root are compared too, so two bare values such as 5 and 6 are reported as a modification.

Worked example with the sample payloads

Compare { "name": "SmartToolPack", "version": "1.0", "status": "active" } with the same object where version is "2.0" and a newFeature: true key is added. The result has two lines: version modified from "1.0" to "2.0", and newFeature added with the value true. name and status are unchanged and are not listed.

Note that the quotes matter. "version": "1.0" is a string, while "version": 1.0 is a number. JSON.parse reads the number 1.0 as 1, so comparing "v": 1.0 with "v": 1 reports no difference, while comparing the string "1.0" with the number 1 is a modification. Type changes like this are a common cause of API bugs that a text diff would hide in plain sight.

Edge cases that catch people out

Because the comparison runs on parsed JavaScript values, a few JSON quirks carry through to the result:

  • Large integers lose precision. JavaScript numbers are exact only up to 9,007,199,254,740,991, so the IDs 9007199254740993 and 9007199254740992 parse to the same value and compare as equal. Send big IDs as strings in APIs for this reason.
  • Duplicate keys in one object are allowed by the parser, but only the last value is kept, so an earlier duplicate is invisible to the comparison.
  • Arrays are ordered and compared by index. [1, 2] and [2, 1] are reported as two modifications, and inserting an item at the start of a long list shows every later position as changed, which is correct for lists but noisy for sets of tags.
  • A change of type, such as an array replaced by an object, is reported once at that path as a modification rather than as a list of added and removed children.

Standard formats for describing JSON changes

If you need to send a diff to another system rather than read it, two standards exist. JSON Patch (RFC 6902) describes changes as a list of operations such as add, remove and replace with a JSON Pointer path like /settings/theme, and it can express array insertions precisely. JSON Merge Patch (RFC 7396) is simpler: you send a partial object, keys with new values overwrite, and keys set to null are deleted. Merge Patch cannot express setting a value to null or editing a single array item.

This tool's paths, such as settings.theme.color, are meant for people to read. Libraries such as jsondiffpatch can produce machine-readable deltas and detect items moved within arrays, which an index-based comparison reports as modifications.

JSON Diff & Compare: frequently asked questions

How do I compare two JSON files ignoring key order?

Use a structural comparison that parses both files rather than a text diff. This tool matches object keys by name at every level, so reordered keys are never reported as changes. On the command line, jq -S sorts keys recursively so that a normal text diff of the two outputs works too.

Why are two identical-looking numbers reported as equal when they are different?

JSON numbers are parsed into JavaScript's 64-bit floating-point format, which is exact only for integers up to 2 to the power of 53 minus 1. Larger values are rounded, so distinct long IDs can become the same number. Compare them as strings instead.

What is JSON Patch?

JSON Patch, defined in RFC 6902, is a JSON document listing operations such as add, remove, replace, move, copy and test, each with a path. It is used in HTTP PATCH requests to update part of a resource without sending the whole thing.

Can I diff JSON with comments or trailing commas?

Not as standard JSON, because the JSON specification does not allow comments or trailing commas. Formats such as JSONC and JSON5 do, so strip comments and trailing commas first, or convert the file with a tool that understands those formats.

All html & javascript utilities