oktools

JSON Diff & Compare

Compare two JSON documents and see every difference as a structured JSON diff: added keys, removed keys and changed values, each with the path it sits at. Both documents stay in your browser; nothing is uploaded.

Valid JSON
Valid JSON

Differences

25%Similarity
+1Added
−2Removed
~3Modified
Original
~{
~"name": "John Doe",
~"age": 30,
~"email": "john@example.com",
−"role": "admin",
~"permissions": [
"read",
"write",
−"delete"
~],
"phone": —
~}
Modified
~{
~"name": "Jane Smith",
~"age": 25,
~"email": "jane@example.com",
"role": —
~"permissions": [
"read",
"write",
—
~],
+"phone": "+1234567890"
~}

How it works

Each side is parsed on its own, as in the formatter: a leading byte-order mark is ignored and a stray no-break space is named in the error under the box. The validity badges follow every keystroke, but the comparison runs 150 milliseconds after typing pauses, since walking two large documents per keystroke is what makes a page stutter. The walk is recursive: identical values are equal, an object against an array or a number against a string is a type change, and two objects are compared over the union of their keys, with a key present on one side only reported as added or removed down to its last leaf.

Arrays are lined up before they are compared. Every item is reduced to a canonical string — its JSON with keys sorted — and the two lists are aligned with a longest-common-subsequence table once matching items at both ends have been settled. A stretch of removed items followed by added ones is paired off in order, so an item edited in place is compared with its counterpart and the changes inside it show at their own paths. The aligned reading is kept only when it reports fewer changes than a plain index-by-index comparison; on a tie, or when the table would exceed four million cells, the positional reading is used.

The result is one tree drawn three ways. Side by side renders it twice with identical rows, so collapsing a branch collapses it in both panes and the scroll positions mirror each other; containers with more than 200 entries start collapsed. Inline merges both sides into one list. Changes only flattens the tree to the leaves that differ, each with its path: dot notation for plain keys, brackets for keys with spaces or dots and for array indexes, which are the item’s index in its own document. Invisible characters are written as \uXXXX escapes, so two strings that differ only by a no-break space do not look identical.

Examples

Find what changed between two API responses

The stats bar reads 67% similarity, +1 added, −0 removed and ~1 modified: four of the six leaves — id, total and both items — came through unchanged. The tracking row shows no old value, because the key did not exist before.

Original and modified
Original:
{"id":7,"status":"pending","total":19.99,"items":["a","b"]}

Modified:
{"id":7,"status":"shipped","total":19.99,"items":["a","b"],"tracking":"ZX1"}
Changes only
~ Modified  status    "pending" → "shipped"
+ Added     tracking  "ZX1"

Compare two documents written in a different key order

One side is minified with b first, the other pretty-printed with a first, and the comparison reports 100% similarity. Formatting and key order are not part of the data, so neither is a difference.

Original and modified
Original:
{"b":1,"a":{"y":2,"x":1}}

Modified:
{
  "a": {
    "x": 1,
    "y": 2
  },
  "b": 1
}
Changes only
No differences
Both documents hold exactly the same entries.

See an inserted array item as one addition

A comparison by position would have called write and delete changed and reported a fourth item added. Matching the three original items by content leaves one row, at the index the new item has in the modified document, and 75% similarity.

Original and modified
Original:
{"permissions":["read","write","delete"]}

Modified:
{"permissions":["read","audit","write","delete"]}
Changes only
+ Added  permissions[1]  "audit"

Catch a number that became a string

Quotes are part of the rendered value, so 8080 and "8080" read differently and are reported as changed even though they look the same in a log. Both leaves changed, so the stats bar shows 0% similarity.

Original and modified
Original:
{"port": 8080, "retries": "3"}

Modified:
{"port": "8080", "retries": 3}
Changes only
~ Modified  port     8080 → "8080"
~ Modified  retries  "3" → 3

Supported formats

  • Any two valid JSON documentsObjects, arrays or single values on either side, and null is a document. Both must parse before a comparison runs; an empty box is labelled Empty rather than Invalid, and the parser’s own message sits under a box that does not parse.
  • Paths in JSONPath notationaddress.city for plain keys, items[3].id for array items, ["a.b"] for a key holding a dot or a space and [""] for an empty key, so a key spelled a.b is never confused with a nested b under a. The $ root is dropped in the Changes only list.
  • Values on one lineEvery value is rendered as JSON on a single line, strings in quotes, so the two panes stay level. Invisible characters are escaped as \uXXXX, and a letter written as base plus combining accent is escaped too, so it cannot pass for its precomposed form.
  • Three views and one set of countsSide by side, Inline and Changes only draw the same tree. Added, removed and modified count leaves — a removed object with three fields counts three — and similarity is the share of leaves that came through unchanged, rounded to a whole percent.

Use cases

  • Compare the same endpoint in two environmentsPaste the staging response on the left and production on the right to see which fields differ, which are missing and which changed type, without the formatting of each server getting in the way.
  • Review a configuration changeAn appsettings.json, a feature-flag export or a Terraform state excerpt from two branches: every key that was added, dropped or given a new value is listed with its path, however each tool serialised the file.
  • Check what a PATCH actually changedCompare the GET before a request with the GET after it. Fields the server rewrote on its own — timestamps, computed totals, normalised strings — show up alongside the ones you sent.
  • Find missing translation keysCompare two locale files. Each Removed row is a key the second language lacks, each Added row one it has that the first does not, whatever order the translators wrote them in.

Limitations

  • Array items are matched by content, not by an idThere is no key field to pair items on, so an item whose id and body both changed appears as a change to the item in that position or as a removal and an addition, never as “item 42 was edited”. Sort both arrays by the id first, or compare the two records on their own.
  • It is not a text diffWhitespace, indentation, key order and the spelling of numbers are invisible here by design, and a document with comments or trailing commas does not parse at all. For those, use Text Compare.
  • The result stays on screenThere is no JSON Patch (RFC 6902) output, no merge and no copy of the diff. For a patch file, format both documents with Sort keys in the JSON formatter and run them through Text Compare, which exports a unified diff.
  • Very long arrays are compared by positionWhen the differing stretch of two arrays would need more than four million table cells — roughly two thousand unmatched items a side — items are compared index by index, and an insertion near the top then shows as a change to everything after it.

Frequently asked questions

How do I compare two JSON files?

Paste one document on the left and the other on the right. Both are parsed and walked key by key, and every difference is listed by its path — what was added, what was removed, and what changed value — rather than as a line-by-line text diff that reflows whenever the formatting differs.

Does the order of keys matter?

No. The comparison is structural, so the same object formatted differently, indented differently or with its keys written in another order reports no differences. That is the main advantage over diffing two JSON files as plain text, where reordering a key looks like a change.

How are arrays compared?

Items are lined up by content first, the way a line diff lines up lines, so an item inserted or removed in the middle shows as one addition or removal rather than as a change to everything after it. Where the two arrays share nothing to line up on, items are compared position by position — an item edited in place is compared with its counterpart, and two swapped items show as two changes. Order still matters: a JSON array is an ordered sequence, so if order is not meaningful in your data, sort both sides before comparing.

Can it compare deeply nested objects?

Yes. The walk is recursive to any depth and each difference is reported with its full path, so you can tell a change at data.items[3].meta.id from one at data.items[4]. Containers can be collapsed, which makes a large diff readable by letting you close the parts that match, and a container with more than 200 entries starts out collapsed so a big document stays quick to draw.

Why does it say two numbers differ when they look the same?

JSON has one numeric type, so 1 and 1.0 parse to the same value and do not differ, but 1 and "1" do — one is a number and the other a string. Values of different types are always reported as changed, which catches the field that quietly became a string somewhere upstream. The one blind spot is integers above 9007199254740991: JavaScript rounds them while parsing, so two long IDs a few apart can compare as equal, and the page warns whenever a document holds one.

Is the data I compare uploaded anywhere?

No. The whole tool is JavaScript running in your own browser, so nothing you type or paste is sent over the network, written to a log or attached to an analytics event. You can confirm it by opening the network tab and watching it stay empty while you work.