How to Compare Two JSON Files
Published:
A text diff can make a small configuration change look large when whitespace or object key order changes. A structural comparison helps answer which values actually changed. Keep the original files available if you also need to review exact formatting.
Load one document into each editor
Open the JSON Diff tool. Paste or upload the original document into the left editor and the modified document into the right editor. Each editor takes a complete JSON document; there is no wrapper object to construct.
Use this original document:
{
"service": "demo",
"replicas": 2,
"features": ["logs"],
"debug": true
}
Use this modified document:
{
"replicas": 3,
"service": "demo",
"features": ["logs", "metrics"]
}
Select Compare JSON. The report should contain three changes: /replicas is modified from 2 to 3, /features/1 is added with value metrics, and /debug is removed. Moving the service property does not count as a change.
Read paths and change direction
JSON Pointer paths identify locations using slash-separated tokens. Array indices start at zero. A property named a/b appears as /a~1b, while a tilde in a property name becomes ~0. An empty pointer identifies the document root. These escape rules come from RFC 6901.
Added and removed are relative to the left-to-right comparison. Use Swap documents to reverse that direction, then run the comparison again. Format both improves readability without changing the intended data comparison. Use Show changes to filter the result by change type, and Previous change or Next change to move between visible changes. Synchronize editor scrolling moves both input editors proportionally. Copy or download the complete report when you need to attach the result to a review; filtering does not alter it.
Understand what the comparison preserves
Object properties are compared by key and arrays by position by default. Reordering an array can therefore produce several changes. Enable Ignore array order to compare array values recursively without regard to order. Duplicate counts still matter: [1, 1, 2] differs from [1, 2]. Unmatched items become additions and removals, with paths pointing to the original index on the corresponding side. Whitespace is ignored, but a number and a string containing digits are different values. The report is structural; it is not a line-by-line editor diff, a JSON Patch document or a three-way merge.
The tool uses JavaScript JSON parsing. Duplicate object keys can be collapsed, and integers outside the safe integer range can lose precision. Keep large identifiers as strings when your schema permits it, and use a precision-preserving workflow when exact large numeric values matter.
Compare formatted copies on the command line
For ordinary configuration JSON, jq can sort object keys before a conventional text comparison:
jq -S . before.json > before.sorted.json
jq -S . after.json > after.sorted.json
diff -u before.sorted.json after.sorted.json
Choose new output filenames to avoid overwriting files you need. This does not sort arrays or reproduce the browser’s change report. See the jq manual for sorting and numeric behavior. A diff exit status of 1 means differences were found; it is not by itself a parsing failure.