JSON diff: compare two JSON files by record, not by line
Compare two JSON documents, match records by key and see exactly which values changed.
Both documents are compared on this device. Neither is uploaded. How your data stays local.
Problems
JSON Mill's JSON diff compares the document in the workspace with a second one you paste or open. When both hold an array of records, it pairs the records by a key such as id or sku instead of by position, so a file that was exported in a different order does not show every record as changed.
The result is a count of added, removed, changed and unchanged records, a table of the changed records with the old and new value of each field, and a list of every other difference by path. Numbers are compared by value and shown in their original text, so 189.00 stays 189.00.
How to compare two JSON files
- JSON diff: compare files and match records by key | JSON Mill. Paste it into the source panel, drop a file on the workspace or press Open file. This page opens in the Diff view.
- JSON diff: compare files and match records by key | JSON Mill. Paste it into Compare with, or press Open file next to that box. The comparison runs as soon as both are valid.
-
JSON diff: compare files and match records by key | JSON Mill. The line above the counts says which key was used, such as
Records matched by sku. Pick another field in Match records by if the guess is wrong. - JSON diff: compare files and match records by key | JSON Mill. Each changed record shows the old value struck through and the new value below it. Choose CSV or Excel and press Export changes to get one row per changed field.
Example: two inventory exports in a different order
The same four products exported on two days. On Tuesday the records come out in a different order and one record lists its fields in a different order too.
[
{"sku": "TENT-2P", "name": "Two-person tent", "price": 189.00, "stock": 14},
{"sku": "LAMP-LED", "name": "Trail lantern", "price": 34.50, "stock": 60},
{"sku": "STOVE-1", "name": "Camp stove", "price": 72.00, "stock": 9},
{"sku": "MUG-STL", "name": "Steel mug", "price": 12.50, "stock": 120}
]
[
{"sku": "MUG-STL", "name": "Steel mug", "price": 12.50, "stock": 120},
{"sku": "STOVE-1", "stock": 9, "name": "Camp stove", "price": 72.00},
{"sku": "TENT-2P", "name": "Two-person tent", "price": 179.00, "stock": 14},
{"sku": "LAMP-LED", "name": "Trail lantern", "price": 34.50, "stock": 60}
]
Records matched by sku
Added: 0
Removed: 0
Changed: 1
Unchanged: 3
Changed record sku TENT-2P
price: 189.00 to 179.00
A line-by-line diff would flag almost every line of these two files. Matched by sku, the only difference is the tent's price. The key was found automatically because every record has a unique sku and none has an id, _id, uuid or handle.
Options
| Option | What it does |
|---|---|
| Match records by | Auto tries id, _id, uuid, handle, sku, key, name and slug, in that order, and uses the first that every record has with unique values. The list also offers any other field of the first record that qualifies, such as email. |
| Ignore array order | Treats arrays that are not matched by key as unordered collections, so [1, 2, 3] and [3, 1, 2] are equal. Off by default, because order matters in most arrays. |
| Export changes | Writes the changed-record table as CSV or an Excel workbook with the columns key, status, field, old and new. Added and removed records get one row holding the whole record as JSON. |
Limits
- Records are matched only in one array: the root array, or the first top-level member that holds an array of objects in both files. Nested arrays are compared by position, or as unordered collections with Ignore array order.
- A key must be a text or number field that every record on both sides has, with no repeated values. Keys inside nested objects, such as
meta.id, cannot be chosen yet. - The page shows the first 500 changed records and the first 1,000 changes by path. Export changes writes every changed record; the change list stops at 5,000 entries, and the counts above it still include everything.
- Both documents must be valid JSON or JSON Lines. If the second one has an error, the line and column are shown; fix it in the box or in the JSON validator.
- Whitespace inside strings counts as a change. There is no option to ignore case or spacing in values.
Questions
- How do I compare two JSON files and ignore the order of records?
- Open the first file, paste or open the second in Compare with, and let the Diff view match records by key. Records are paired by their
id,skuor other key wherever they sit in the array, so a different order is not reported as a change. - Is 1.0 the same as 1 in the diff?
- Yes. Numbers are compared as exact decimal values, so
1.0equals1and1e2equals100, while long IDs such as9007199254740993are never rounded the way JavaScript rounds them. The old and new values are always shown in their original text. - Does key order inside an object count as a change?
- No. Two objects with the same keys and values are equal whatever order the keys are written in. If a key appears twice in one object, the last value counts, the same way
JSON.parsereads it. - What happens when the files have no common key?
- The Diff view compares the documents by path instead: every added, removed or changed value is listed with its path, such as
$.settings.retries, and its old and new value. You can still pick a key yourself if a field qualifies. - Can I compare JSON Lines files?
- Yes. A JSON Lines file is read as an array of its records, so two exports of the same records in
.jsonlform are matched by key like any other array.
Related tools
Last updated