Skip to main content
ponderloop

JSON Diff

Paste two JSON documents and see what differs by structure, not by line: each added, removed and changed value is listed with its JSON Pointer path (RFC 6901). The example compares two small configs whose keys are in a different order and finds 2 added, 1 removed and 3 changed; the reordered keys and the 1 that became 1.0 are not differences. A patch that turns A into B (RFC 6902) is ready to copy, and invalid JSON is reported with its line and column. Everything runs in your browser, so nothing is uploaded.

Updated Runs in your browser: nothing you enter is uploadedHow this tool works

Replace the two examples: paste or type. The differences update as you type.

Stays in your browser

Your JSON is compared on this device and never uploaded. It is not saved either: reload the page and it is gone. Limit: 500,000 characters per document.

Options

Key order is always ignored: a JSON object is an unordered collection of members (RFC 8259).

Differences

6 differences: 2 added, 1 removed, 3 changed.

Each line starts with + added, − removed or ~ changed, then the key, its JSON Pointer and the value. Removed and changed pointers point into A; added pointers point into B.

  • (document)
  • changedport/port8080 → 9090
  • tags
  • added[2]/tags/2"v2"
  • owner
  • changedteam/owner/team"platform" → "infra"
  • servers
  • [1]
  • changedweight/servers/1/weight2 → 3
  • removeddebug/debugtrue
  • addedregion/region"eu"

Summary

Added
2
Removed
1
Changed
3

JSON Patch (RFC 6902)

Three ways to compare arrays

The same two lists, [{"id":1,"name":"ann"},{"id":2,"name":"bo"},{"id":3,"name":"cy"}] and [{"id":3,"name":"cy"},{"id":1,"name":"anna"},{"id":4,"name":"di"}], compared each way.
OptionResultReportedHow it works
By position0 added, 0 removed, 6 changed~ /0/id, ~ /0/name, ~ /1/id, ~ /1/name, ~ /2/id, ~ /2/nameElement 0 is compared with element 0, and so on. A reordered list shows up as changes in every position.
As unordered sets2 added, 2 removed, 0 changed− /0, − /1, + /1, + /2Equal elements pair up wherever they are; what is left over on each side is removed or added. Nothing is reported as changed inside an element.
By an id key1 added, 1 removed, 1 changed~ /0/name, − /1, + /2Objects with the same "id" are compared with each other, so a changed field is reported inside the element, however the list was reordered.

When 1 and 1.0 are the same number

Numbers are compared as exact decimals read from the text, never through a floating-point number, so long digit strings are not rounded together.
ABEqual as decimalsEqual as written
11.0yesno
1001e2yesno
0.55E-1yesno
2.502.5yesno
0-0yesno
11.0000000000000001nono
1234567890123456789012345678901234567891nono
1"1"nono

How a key becomes a JSON Pointer

Each row is a key inside an object at the top of the document; its pointer is shown with the escapes RFC 6901 requires.
KeyPointerWhy
name/nameAn ordinary key is used as it is.
a/b/a~1bA slash would end the token, so it is written ~1.
m~n/m~0nA tilde is written ~0.
~1/~01The tilde is escaped first, so a literal ~1 becomes ~01 and is not read as a slash.
(empty)/The empty key is a valid token: the pointer is just “/”.
a b/a bSpaces and other characters need no escaping in the pointer text.

Which patch operation each difference becomes

Each pair is compared with the default options; the patch is the RFC 6902 document the tool writes.
DifferenceABPatch
A key only in B{"a":1}{"a":1,"b":2}[{ "op": "add", "path": "/b", "value": 2 }]
A key only in A{"a":1,"b":2}{"a":1}[{ "op": "remove", "path": "/b" }]
A different value{"a":1}{"a":2}[{ "op": "replace", "path": "/a", "value": 2 }]
A different type{"a":[1]}{"a":"x"}[{ "op": "replace", "path": "/a", "value": "x" }]
Longer array (by position)[1][1,2][{ "op": "add", "path": "/1", "value": 2 }]
Shorter array (by position)[1,2,3][1][{ "op": "remove", "path": "/2" }, { "op": "remove", "path": "/1" }]
The whole document differs[1]{"a":1}[{ "op": "replace", "path": "", "value": {"a":1} }]

How to compare two JSON documents

  1. Paste both documents. Put the original in box A and the changed version in box B. The comparison updates as you type.
  2. Choose how arrays are compared. Pick by position, as unordered sets, or by an id key. For a list of records, the id key pairs each record with its counterpart even if the order changed.
  3. Set the other options. Leave “1 and 1.0 are equal” on to compare numbers as exact decimals, and tick the whitespace option to ignore differences that are only spaces, tabs or line breaks inside strings.
  4. Read the differences. The summary counts what was added, removed and changed. In the tree, every difference carries a + (added), − (removed) or ~ (changed) marker and a word as well as a colour, with its JSON Pointer path.
  5. Copy the patch. Copy the JSON Patch to apply the changes to A with any RFC 6902 library. If a box shows an error, fix the JSON at the line and column given.

Frequently asked questions

How is this different from comparing the text?
A text diff compares lines, so reformatting, a different indent or reordered keys make everything look changed. This tool reads both documents as JSON and compares values: object keys have no order (RFC 8259 says an object is an unordered collection), and whitespace between tokens does not exist in the data. Only real differences in values are reported.
What is a JSON Pointer?
A string that names one value in a document (RFC 6901). “/servers/1/weight” means the “servers” member, its element 1 (counting from 0) and that element’s “weight”. The empty string names the whole document, and in a key “~” is written “~0” and “/” is written “~1”. Removed and changed paths point into A; added paths point into B.
What is the JSON Patch for?
It is a list of add, remove and replace operations (RFC 6902) that, applied to A, gives B. Libraries for most languages can apply one, so you can ship a small change instead of the whole document. Because the options decide what counts as equal, the patch only fixes differences the tool reports: with unordered arrays, for example, the result has the same elements as B but may list them in A’s order.
How do the array options differ?
By position pairs element i of A with element i of B, which is right when order matters. As unordered sets ignores order and treats duplicates as counts. By an id key pairs objects that share the same value for a key you name (“id” by default), so a record that moved is compared with itself and only its changed fields are reported. Records without that key are compared as an unordered set, and a note says how many.
Are 1 and 1.0 the same number?
In JSON they are the same number written two ways, so by default they are equal, as are 100 and 1e2. The tool compares the exact decimal read from the text, with no rounding: 12345678901234567890 and 12345678901234567891 stay different, which a comparison through floating-point numbers would get wrong. Turn the option off to compare the text as written. Negative zero equals zero.
What does ignoring whitespace-only differences do?
For string values it trims the ends and treats any run of spaces, tabs and line breaks as one space before comparing, so "a b" and " a b " are equal while "ab" and "a b" are not. Keys are never changed, and whitespace between JSON tokens is never part of the comparison anyway.
What if a key appears twice in one document?
JSON does not define what duplicate keys mean (RFC 8259 only says names SHOULD be unique). This tool keeps the last value, as most parsers do. Use the JSON Formatter to list duplicate keys first if that matters.
Is there a size limit?
Yes: 500,000 characters (about 500 KB) per document. Above that the page shows a notice instead of comparing, so the tab stays responsive. The tree lists the first 1,000 rows; the patch always lists every change.
Is my data uploaded anywhere?
No. Both documents are read and compared in your browser and are never uploaded, stored or logged; they are gone when you close or reload the page. The only thing the site records, if you allow analytics, is that a button was used, never any of the data.

How it works

Both documents are read by a strict RFC 8259 parser that keeps each number as the text that was written and reports an error with its line and column. The two values are then walked together. Objects are matched by key, so order is ignored. Values of different types, and scalars that differ, are reported as changed; a key only in A is removed and a key only in B is added. Numbers are turned into a canonical form (sign, significant digits and a power of ten) so that 1, 1.0 and 1e0 are equal without rounding. Arrays are compared by index, or as unordered sets (equal elements pair up one-to-one, so duplicates count), or by the value of an id key (elements with the same id are compared with each other, the rest as a set). Every difference is named by a JSON Pointer (RFC 6901). The same walk writes an RFC 6902 JSON Patch: replace for a changed value, remove and add for keys, changes inside kept array elements first, then removals from the highest index down, then additions; elements added to an unordered or id-keyed array are appended with the “-” index. Input above 500,000 characters per document is not compared.

Sources

More: Formatters and data convertersAll developer toolsAll toolsHome & DIY calculators