JSON diff

Compare two JSON objects and get the differences between them.

loading JSON diff
About this tool

What is a JSON diff tool?

A JSON diff tool compares two JSON documents by their structure and tells you which keys were added, which were removed and which values changed. That is different from a plain text diff. If two files hold the same data but one has its keys in another order, or one is minified and the other indented, a text diff lights up every line, while a JSON diff correctly says that nothing changed.

You reach for it in everyday work: to see what a new API version changed in a response, to check a config file before and after a deploy, to compare a fixture with what a test actually received, or to review a package.json or a feature-flag export that two people edited. Differences are reported with the path to each value, so you can read them without searching a long document by eye.

Both documents are read in your browser and never uploaded. The reader is also forgiving: it accepts JSON5, so comments, single quotes, unquoted keys and trailing commas do not stop the comparison. That matters when one side is a hand-edited config and the other is strict output from a service. When you only need to compare plain text, such as logs or source files, use the text diff instead.

How to compare two JSON files online

  1. Paste the original document in the first box and the one to compare in the second. The page opens with two small examples, so you already see a result and can edit it in place.
  2. The comparison runs a moment after you stop typing, so even large documents do not freeze the keys. If one of the two is not valid, a message says which box has the problem and the line and the column to check.
  3. Read the result card. Added values are shown in green, removed values in red and struck through, and a changed value shows the old one, an arrow and the new one. Objects and arrays that contain changes are expanded; identical parts stay quiet.
  4. Turn on the switch that shows only the differences to hide everything that is the same. This is the setting to use on a document with hundreds of keys.
  5. Choose how array items are paired. By content matches equal items wherever they sit, so an item inserted at the start counts as one addition. By position pairs item 0 with item 0, item 1 with item 1, and so on, which is what you want when the order is the meaning.
  6. Press the copy button for the differences to get them as plain lines, ready to paste in an issue or a chat. The two choices above are remembered for your next visit; the JSON you paste is not.

If you want to tidy a document before comparing it, run it through the JSON formatter first.

Examples

A version bump and a new field

The default example. The first document has version 1 and the tags a, b; the second has version 2, the tags a, c and a new private field. Copied differences:

~ version: 1 -> 2
~ tags[1]: "b" -> "c"
+ private: true

A line starting with + is an addition, - a removal and ~ a change.

An item inserted at the start of a list

Documents {"ids":[1,2,3,4]} and {"ids":[0,1,2,3,4]}. Pairing by content gives a single line:

+ ids[0]: 0

Pairing by position compares item against item and reports a change in every slot:

~ ids[0]: 1 -> 0
~ ids[1]: 2 -> 1
~ ids[2]: 3 -> 2
~ ids[3]: 4 -> 3
+ ids[4]: 4

Same data, two readings. Use the first for sets of records and the second for fixed positions such as coordinates.

The same items in a different order

{"roles":["admin","dev","ops"]} against {"roles":["ops","admin","dev"]} is reported as a reorder, not as three edits:

~ roles: same items, different order

Nested objects and null

{"a":{"b":1,"c":[1,2]},"x":null} against {"a":{"c":[1,2],"d":"new"},"x":0}:

- a.b: 1
+ a.d: "new"
~ x: null -> 0

The array c is equal on both sides and does not appear. Note that null and 0 are different values.

Common errors and how to fix them

  • The first JSON is not valid: check line 1, column 9: for example {"a": 1,, } has a double comma. Fix the spot named and the comparison runs again.
  • The second JSON is not valid, line 1, column 8: {"a": 1 stops before the closing brace. Copy the whole document.
  • Nothing is shown below the boxes: one of the boxes is empty or invalid. The comparison needs a readable document on both sides.
  • Everything looks different: check the type. The string "42" and the number 42 are different values, and so are "true" and true.

Frequently asked questions

How do I compare two JSON files?

Paste the first in the top box and the second in the bottom box. The differences appear below, with the path of every added, removed or changed value. To work from files, open them in an editor and copy the contents.

Does the order of keys matter?

No. Objects are compared key by key, so {"a":1,"b":2} and {"b":2,"a":1} are the same. Arrays are different: by default equal items are matched anywhere, and with the by position setting the order counts.

Can I compare JSON with comments?

Yes. The reader accepts JSON5, so comments, single quotes and trailing commas are fine. They are not data and never appear in the differences.

Is my data sent to a server?

No. Reading and comparing happen in your browser. The only things saved on your device are the display choices, not the JSON.

How do I compare YAML or other formats?

Convert them first: YAML to JSON and JSON to YAML give you JSON on both sides. For free text, use the text diff.

How to compare JSON in code

JavaScript

Node can compare two parsed values with assert.deepStrictEqual, which throws a readable message when they differ, and ignores key order.

import assert from 'node:assert/strict';

const a = JSON.parse('{"name":"toolbox","version":1}');
const b = JSON.parse('{"version":1,"name":"toolbox"}');
assert.deepStrictEqual(a, b); // same data, different key order: passes

Python

Dictionaries compare by content, regardless of key order. For a path-by-path report, the deepdiff package does it.

import json

a = json.loads('{"name": "toolbox", "version": 1}')
b = json.loads('{"version": 2, "name": "toolbox"}')
print(a == b)  # False
print({k for k in a.keys() | b.keys() if a.get(k) != b.get(k)})  # {'version'}

Bash

With jq, sort the keys of both files and let diff do the rest.

diff <(jq -S . before.json) <(jq -S . after.json)
Report a problem