DevTools Logo

JSON Diff

JSON Diff

Compare two JSON documents structurally — path-addressed differences, type changes, and array matching that survives insertions.

Try a sample:

Index pairs position by position. LCS aligns arrays by content first, so an insertion at the front reads as one add instead of a shift of every element.

Examples

API response drift

Input
{"users":[…2 items],"total":2,"cursor":null} vs {"users":[…3 items],"total":3,"cursor":"nxt","page":1}
Output
+ $.users[2] · ~ $.total 2 → 3 · T $.cursor null → "nxt" · + $.page 1

One glance shows the contract shift: a new record, a new field, a replaced count, and a cursor that changed type.

Config drift across environments

Input
{"port":5432,"tls":{"enabled":false}} vs {"port":"5432","tls":{"enabled":true,"cert":"/etc/cert.pem"}}
Output
T $.port number → string · ~ $.tls.enabled false → true · + $.tls.cert "/etc/cert.pem"

The port's quote change is a type change, not a cosmetic edit — exactly what a line diff buries.

Front insertion with LCS

Input
["a","b","c"] vs ["new","a","b","c"]
Output
+ $[0] "new" (LCS mode)

Index mode reports three replaces and an add; LCS matches the shared elements and shows the single insertion.

About this tool

Two JSON documents can look almost identical line by line and still mean completely different things to your application. The JSON Diff compares them structurally: it parses both documents, walks objects by key and arrays by a matching strategy you control, and reports every difference as a path-addressed operation — add, remove, replace, or type change — addressed the way your code addresses it, like $.users[3].name. Instead of scrolling through red and green lines and mentally re-deriving where a change lives, you read a list of paths that a test assertion, a TypeScript fix, or a jq command can use directly.

Type changes get their own category because they are the most dangerous class of drift. A line diff sees "5432" becoming 5432 as one nearly invisible quote; a structural diff knows the port went from a string to a number and flags it as a type change. The same goes for null turning into an object, an object turning into an array, or a boolean becoming a string — all shapes that pass a text comparison quietly and then break deserialization loudly in production.

Arrays are where text diffs lie the most. Insert one element at the front of a list and every line changes, so a naive comparison reports the whole array as rewritten. The JSON Diff offers two matching modes: index pairing compares position by position, which is predictable and fast, while LCS (longest common subsequence) alignment matches elements by content first, so the same insertion reads as a single add at $.log[0] and the untouched elements stay silent. Choose index mode when position matters semantically; choose LCS when the array is a set-like collection where membership matters more than order.

The comparison runs entirely on your device — documents are parsed and diffed in your browser and never sent to a server, with only the raw pastes persisting locally between visits. Input is validated with JSON.parse on each side, so a syntax error points at the offending document before any diffing starts, and pastes over the 1MB budget trigger an explicit size warning. The result view toggles between side-by-side (old and new value per path) and a compact inline list, both color-coded: green for additions, red for removals, amber for replacements, violet for type changes. Structurally equal documents earn an identical badge, and the whole op list copies as plain text for bug reports, PR descriptions, or migration notes.

What this tool does not do

  • Compares parsed values only: whitespace, key order and duplicate keys (last one wins in JSON.parse) are invisible by design.
  • LCS alignment costs O(n×m) on array length — extremely large arrays fall back to index pairing to stay responsive.
  • Output is an operation list, not a merged document — for applying patches to text files, the Code Diff Patch Generator handles that side.

How to use this tool

  1. Paste both documents

    Put the original JSON in the left field and the changed JSON in the right field. Each side is validated with JSON.parse as you type — syntax errors name the offending document.

  2. Pick the array matching mode

    Leave Index for position-sensitive arrays or switch to LCS when elements can be inserted or reordered and you want content-based alignment.

  3. Read the path-addressed results

    Each row is one operation: + add, − remove, ~ replace, T type change, addressed like $.users[3].name. Switch between side-by-side and inline views as needed.

  4. Copy the differences

    Use Copy differences to put the plain-text op list on your clipboard for a bug report, PR description, or migration checklist.

Use cases

Comparing API responses

Diff yesterday's and today's payloads for the same endpoint to catch contract drift — new fields, dropped fields, and type changes — before clients break.

Auditing config drift

Compare two environment configs or two copies of a settings file by path to see exactly which keys differ and whether any change altered a value's type.

Reviewing fixture and snapshot changes

When a test snapshot or fixture JSON changes, read the structural difference directly instead of parsing a wall of line-level red and green.

The four structural operations

OperationMeaning
+ addPath exists only in the changed document; the value shown is new
− removePath exists only in the original document; the value shown is what disappeared
~ replaceSame JSON type, different value — the drift is in the data
T type changeDifferent JSON type (number vs string, null vs object, array vs scalar) — the drift is in the shape
Path syntax$ is the root; .key walks objects; [3] indexes arrays — matching jq and JSONPath conventions

Keys that are not valid identifiers are quoted: $["weird key"] — valid JSONPath addressing regardless of key name.

Common mistakes

Mistake:Reading a text diff as if it were a structural diff.

Fix:Line diffs reformat, re-indent and reorder freely, drowning real changes in noise. A structural diff compares parsed values, so whitespace and key order never register as changes.

Mistake:Assuming index mode means array elements correspond.

Fix:Index pairing trusts position. If elements can be inserted, removed or reordered, switch to LCS so shared content is matched before differences are reported.

Mistake:Overlooking type changes in numbers and strings.

Fix:5432 and "5432" serialize differently and consumers behave differently. Treat every T row as a breaking change candidate and fix it before shipping.

Frequently asked questions

What does a path like $.users[3].name mean?

It is a JSONPath-style address: $ is the root document, .users walks into the users object key, [3] is the fourth element of that array (zero-indexed), and .name is a key inside that element. You can read it as a recipe: start at the root, take the users array, take element 3, take its name. Paths that are not valid JavaScript identifiers are quoted instead, like $["weird key"], so the address stays unambiguous for any key name.

How is a structural JSON diff different from a text diff?

A text diff compares lines, so re-indenting, reordering keys, or reformatting whitespace all register as changes, and a value moved from line 40 to line 120 looks like a removal plus an addition. A structural diff parses both documents first and compares parsed values, so formatting never registers and changes are reported at their semantic path — $.settings.timeout changed from 30 to 60. For JSON specifically, the structural view answers the question you actually have: what data or shape changed.

When should I use index array matching versus LCS?

Use index mode when position is meaningful — a queue, a priority list, or an API whose contract fixes which index holds what. Use LCS when the array behaves like a collection where membership matters more than order: logs, tags, IDs, or any list where elements get inserted or removed in the middle. LCS aligns elements by content first, so inserting an item at the front is reported as one add rather than every element shifting and being reported as changed.

Why are type changes reported separately?

Because they are usually bugs or breaking changes, not intentional data updates. A port going from 5432 to "5432", a null becoming an object, or an array becoming a string will often pass a text comparison unnoticed but break deserialization, database inserts, or strict TypeScript types. Flagging them as their own operation (T) makes them impossible to skim past, and each one deserves a closer look than an ordinary value replace.

How large can the JSON documents be?

The tool warns when either paste exceeds 1MB of text, because deep structural comparison over very large documents can become slow, and LCS array matching is the most expensive part. Practical everyday payloads — API responses, config files, test fixtures — diff instantly. For very large exports, extract the relevant subtree first, or accept index mode, which the tool uses internally as a fallback when an array pair would be too large to align with LCS.

Is my JSON sent to a server?

No. Parsing and diffing happen entirely in your browser — the tool is static client-side code with no backend, so your documents never leave the device. The only storage is your own browser's localStorage, which keeps the raw pastes between visits so you can resume a comparison; clearing a field or using your browser's site-data controls removes it. This makes the tool safe for internal API payloads and configs you would not paste into a web service.

References & standards