Comparing two JSON files sounds like a job for a normal diff, but JSON isn't plain text. Two files can hold exactly the same data and still look completely different, because keys are in another order or the indentation changed. Take these two:
{"name":"Ann","age":30,"tags":["a","b"]}{
"age": 31,
"name": "Ann",
"tags": ["a", "b"],
"active": true
}A line-by-line diff marks every line as changed. In reality there are only two changes: age went from 30 to 31, and active was added.
Compare JSON online
Paste the two documents into JSON Diff. It compares the data, not the text, so key order and whitespace never show up as changes. You get each addition, removal and change with its path, a unified or side-by-side view, and the differences as a JSON Patch you can copy. Both documents stay in your browser, which matters when you're comparing API responses or production config.
On the command line with jq
Normalise both files with jq -S (sort keys, consistent formatting) and diff the results:
diff <(jq -S . a.json) <(jq -S . b.json)2c2,3
< "age": 30,
---
> "active": true,
> "age": 31,In Python
Parsed JSON objects become dictionaries, and dictionary equality ignores key order:
import json
with open("a.json") as f: a = json.load(f)
with open("b.json") as f: b = json.load(f)
print(a == b) # False: the data differs
print({"x": 1, "y": 2} == {"y": 2, "x": 1}) # True: key order doesn't matter
print([1, 2] == [2, 1]) # False: array order doesThat tells you whether they differ, not where. For a list of differences, libraries such as DeepDiff report each changed path.
In JavaScript
Don't compare JSON.stringify output: it depends on key order, so equal objects can produce different strings. In Node.js, use the built-in deep comparison:
import { isDeepStrictEqual } from "node:util";
isDeepStrictEqual({ x: 1, y: 2 }, { y: 2, x: 1 }); // true
JSON.stringify({ x: 1, y: 2 }) === JSON.stringify({ y: 2, x: 1 }); // falseDescribing the differences as JSON Patch
JSON Patch (RFC 6902) is the standard way to write differences down: a list of operations that turn the first document into the second. For the example above:
[
{ "op": "replace", "path": "/age", "value": 31 },
{ "op": "add", "path": "/active", "value": true }
]Patches are useful for audit logs, syncing data and HTTP PATCH requests. JSON Diff generates one for any two documents.
Tips for cleaner comparisons
- Arrays are ordered. If order doesn't matter in your data (like a list of tags), sort both arrays first, or use JSON Diff's option to ignore array order.
- Ignore noise. Timestamps and generated IDs change on every response; remove them before comparing so the real differences stand out.
- Format first when reading by eye. The JSON Formatter makes minified responses readable, and Deep Search finds a key's path in a big document.