Browser-based developer tool · nothing is uploaded

JSON Diff

Paste or open two JSON documents and see what changed in meaning: key order is ignored, arrays can be matched by position, by an id field or by value, and any path can be left out. Export the result as an RFC 6902 JSON Patch or a Markdown report.

Document A

The original (patch starts from this)

Document B

The new version

Comparison rules

Object key order is always ignored.

a.b.c is an exact path, items[*].price covers every item, [2] one index, * one level, ** any depth. A bare name such as updatedAt matches at any depth.

Result

6 differences

Added
2
Removed
1
Changed
3
Unchanged
7
Ignored
1
  • (root) +2 −1 ~3
    • ~price: 19 → 24
    • tags ~1
      • ~[1]: "monthly" → "annual"
    • features +1 −1 ~1
      • [id=storage] ~1
        • ~limit: 50 → 100
      • −[id=support]: {"id":"support","limit":1}
      • +[id=api]: {"id":"api","limit":10000}
    • +trial: true

JSON Diff and JSON Patch Generator

Operator: Abdulla Al Fahad. How tools are built and checked

A plain text diff of two JSON files is rarely what you want. Reorder the keys, re-indent the file or let a serializer add a trailing newline and every line shows up as changed, while the one value that actually moved sits somewhere in the noise. This tool reads both documents as data first and compares what they mean: the same keys with the same values are equal whatever order they were written in. The Text Compare tool marks line and word edits in ordinary prose, and Diff CSV matches the rows of two spreadsheets; this one understands JSON structure, so it can ignore key order and line up array items by id.

You decide how arrays are lined up, because that is where JSON comparison gets ambiguous. A list of line items can be matched by position, by an identifying field such as id, or as an unordered collection of values. You can also name paths to ignore, such as a last-updated timestamp, so that the result shows only the changes you care about. The outcome can be read as a tree or side by side, and exported as an RFC 6902 JSON Patch or a Markdown report.

Key features

  • Strict JSON parsing with the line, column and a caret under the offending character when a document is invalid
  • Object key order is always ignored; arrays can be matched by position, by a key field (dotted paths allowed) or by value, ignoring order
  • Ignore paths with exact paths, [*] and [n] indexes, * for one level, ** for any depth, and bare names that match anywhere
  • Four views of the result: collapsible tree, side-by-side lines, a flat change list and the JSON Patch
  • Download an RFC 6902 patch of add, remove and replace operations, which the page checks by applying it to document A and re-comparing
  • Download a Markdown report with counts, the settings used and every difference with its path

Matching rules, ignored paths and the patch operations

Each document can be up to 20 MB and is parsed by a reader written for this page rather than JSON.parse, so the error message is the same in every browser and always carries a line and column. Typical messages: a trailing comma before a closing bracket, a single-quoted string or key, a comment, a missing comma between members, a raw line break inside a string, or text after the end of the value. A byte-order mark at the start is ignored. Nesting deeper than 400 levels is refused. Numbers are read as ordinary double-precision values, so 1 and 1.0 are equal but integers beyond 2^53 lose precision, as they do in any JavaScript tool. If an object repeats a key, the last occurrence wins and no warning is given.

Comparison is by type and value. The string "1" and the number 1 are different, and null is different from a missing key: a key present in one document and absent from the other is reported as added or removed, never as changed. The summary counts leaf differences, so a whole object that exists only in B counts as one added entry, not one per field, and unchanged values are counted too.

In key mode every item in both arrays must be an object with a unique, non-empty string, number or boolean in the key field; the field name may be a dotted path such as user.id. If any item fails that test the array is compared by position instead and a note names the array, so a single bad row cannot silently produce a nonsense result. Arrays of plain values such as tags fall back to position quietly. Matched items are compared field by field, items found only in A are removed and items found only in B are added. The order of matched items is not compared. Value mode matches equal items one-to-one, so two identical entries in A need two in B.

Ignore patterns are tested against each path as the comparison walks the documents, and anything that matches is skipped entirely, children included; the count of skipped nodes is shown. meta.updatedAt and $.meta.updatedAt mean the same exact path, items[*].price covers the price of every item, items[2] covers the third item, * stands for one level and ** for any number of levels, and a bare name with no dot or bracket such as updatedAt matches at any depth.

How it works

The comparison builds a tree. Each node records whether it is unchanged, added, removed or changed, where it sits in A and in B, and for containers the child nodes. The tree view, the side-by-side listing, the change list, the report and the patch are all drawn from that one tree, so they cannot disagree with each other.

The patch is generated from the same tree. Inside an array, edits to matched items are written first using their positions in A, then removals from the highest index down so earlier indexes stay valid, then additions at their position in B or appended. After building the patch the page applies it to a copy of A and compares the result with B under the same rules; a green check means zero differences remain. With key or value matching the patched array may hold the same members in a different order than B, because that comparison ignores order; that is stated with the check result. Ignored paths are never patched.

Common use cases

  • Comparing a staging API response with production and finding that only a price and one feature entry differ, after ignoring the response timestamp
  • Reviewing a configuration file before and after a deploy when the tool that writes it re-sorts the keys every time
  • Checking that a data export still has the same records after a schema migration, matching rows by id rather than by position
  • Producing a JSON Patch that a client can apply to turn the stored document into the new one, instead of sending the whole thing

How to use this tool

  1. Paste JSON into Document A and Document B, or use Open file. The built-in example loads with Load example.
  2. If either document is invalid, read the line and column in the red box and fix it; the comparison starts as soon as both parse.
  3. Choose how array items match: by position, by a key field such as id, or by value.
  4. Add paths to ignore, one per line, for example meta.updatedAt or items[*].etag.
  5. Switch between Tree, Side by side, Change list and JSON Patch to read the result.
  6. Download the JSON Patch or the Markdown report.

Example

Plan A and plan B, matched by id, ignoring meta.updatedAt

A: price 19, tags [billing, monthly],
   features: seats 5, storage 50, support 1
B: price 24, tags [billing, annual],
   features: storage 100, seats 5, api 10000,
   trial: true, keys in a different order
Options: key field id, ignore meta.updatedAt

Result: 3 changed, 1 removed, 2 added, 1 ignored

changed  $.price                        19 -> 24
changed  $.tags[1]                      "monthly" -> "annual"
changed  $.features[id=storage].limit  50 -> 100
removed  $.features[id=support]
added    $.features[id=api]
added    $.trial

Patch: replace /price, replace /tags/1,
replace /features/1/limit, remove /features/2,
add /features/2, add /trial

Tips for best results

  • Match by a key field whenever the array holds records. Position matching reports every row as changed after a single insertion near the top, which is rarely the truth.
  • Add volatile paths to the ignore list early: timestamps, request IDs, etags and generated hashes. The ignored count tells you how much was skipped, so a pattern that matches too widely is easy to spot.
  • Use value mode for sets, such as a list of permission names, where order carries no meaning.
  • Use Swap A and B to produce the reverse patch.
  • For a very large pair, wait for the Updating note to disappear before reading the counts; the comparison reruns 350 milliseconds after you stop typing.

Common pitfalls

A numeric key field and a string key field do not match: id 7 and id "7" are different keys, so the item shows as removed and added.

Large integers such as 64-bit identifiers lose precision when read as numbers. Two different IDs beyond 2^53 can compare as equal. Store them as strings if exactness matters.

The patch uses only add, remove and replace. It never emits move, copy or test, so a reordered item inside a position-matched array appears as replaced values rather than a move.

In key and value mode the patched array can come out in a different order than document B. If order matters to the consumer, use position matching or reorder afterward.

Common errors and how to fix them

"A trailing comma before ']' is not allowed in JSON"
Remove the comma after the last item. Many editors and JavaScript objects allow it; JSON does not.
"Strings and keys must use double quotes"
Replace single quotes with double quotes. A Python dict or JavaScript object literal pasted as-is will trigger this.
The array at items has items without a unique "id", so it was compared by position
Check for a missing id, a duplicate id or an id that is itself an object. Fix the data, choose a different key field, or use position or value matching on purpose.
The patch check turns amber
Report the pair of documents if it persists. It means applying the generated operations did not reproduce B under your rules, which the page treats as a fault rather than a normal result.

Best practices

  • Keep the same ignore list for repeated comparisons of the same API so a clean result always means the same thing.
  • Save the Markdown report with a ticket when a difference is deliberate, so the reviewer sees the settings as well as the changes.
  • Treat a JSON Patch as a statement about structure, and apply it only to a document that is the same as the A you compared.

Where the documents live while you work

Both documents stay in this tab. Nothing is uploaded, nothing is written to browser storage, and closing the tab discards them. The downloaded patch and report are generated from memory when you press the button.

The side-by-side listing shows at most 4,000 lines and the change list at most 2,000 rows to keep the page responsive; the report and the patch always contain every difference.

Frequently asked questions

Does key order matter?

No. Objects are compared key by key, so two documents that differ only in key order are reported as equal. Array order matters unless you choose key or value matching.

Can I compare two JSON files without pasting them?

Yes. Use Open file above each box. Files up to 20 MB are read directly from your disk.

Is the output a valid RFC 6902 patch?

It is a JSON array of add, remove and replace operations with JSON Pointer paths, which is the format RFC 6902 defines. The page applies it to document A to check that it reproduces B.

Why does a changed array item show as removed and added?

In key mode, an item whose key field changed has a different key, so it no longer matches its old self. Compare by position if the key itself is what you are editing.