JSON Diff
Compare two JSON documents by meaning and list every changed value by its path.
By Syed Mubashir Ali · Last updated
A JSON diff that ignores key order
Try an example compares two versions of a small service config. The second version has its keys in a different order, its port written as a string, a new feature in the list, a bigger database pool and the two owners swapped round with one role changed. A text diff marks most of the file. JSON Diff lists six differences:
~ $.version: "2.3.0" → "2.4.0" ~ $.port: number 8080 → string "8080" + $.features[2]: "gift-cards" ~ $.database.pool: 10 → 20 ~ $.owners[0].role: "dev" → "lead" ↕ $.owners: item order id=1, id=2 → id=2, id=1
- JSON Formatter: Tidy or validate a JSON file before comparing it.
- Diff Checker: Compare plain text, logs or code line by line instead.
What counts as a difference
A changed value is reported at its path with the old and new value. A key present on only one side is added or removed; a key that's null on one side and missing on the other is still a removal, because null is a value. A value that changed type, such as the number 8080 becoming the text "8080", is a type change, the kind of edit that breaks a strict API client without looking like one.
Lists are compared in order, so an item inserted near the top is one addition rather than a change to every item below it. When every item in a list is a record with a unique id (an id, _id, key, uuid or name field), records are matched by that id, so a moved record isn't reported as removed and added, and the move itself shows as an order change. Tick Ignore array order when order doesn't matter, as with a list of tags.
How to Use JSON Diff
- 1Paste the original JSON on the left and the changed JSON on the right, or open a .json file into either side. Try an example fills both with a sample.
- 2If either side isn't valid JSON, the line and column of the problem appear under that box, with a caret under the mistake.
- 3Read the Changes list: each difference is listed by its path, such as $.address.zip, with the old and new value. Filter it to changed, added or removed values.
- 4Leave Ignore key order on to skip keys that only moved; tick Ignore array order when a list is really a set, such as tags.
- 5Switch to Side by side to see both documents formatted the same way, keys sorted, with only the real changes highlighted.
- 6Copy the changes as text, or copy or download them as a JSON Patch (RFC 6902) to apply the same change elsewhere.
Frequently Asked Questions
Why doesn't a different key order count as a change?
JSON objects have no order: {"a":1,"b":2} and {"b":2,"a":1} hold the same data, and every JSON parser reads them the same way. So key order is ignored by default. Untick Ignore key order to see where it changed, for the rare case where something compares the raw text.
How are arrays compared?
Lists keep their order, and an item inserted near the start is reported as one addition, not as a change to every item after it. When every item is a record with a unique id (an id, _id, key, uuid or name field), records are matched by that id wherever they moved, so you see which fields changed. Tick Ignore array order to treat a list as a set.
Are 1 and 1.0 the same number here?
Yes. Numbers are compared by value from their exact digits, so 1, 1.0 and 1e0 match. Long IDs aren't rounded the way JavaScript's JSON.parse rounds numbers beyond 2^53, so two 20-digit IDs that differ only in the last digit are reported as different.
What is a JSON Patch?
A list of add, remove and replace operations, defined in RFC 6902, that turns one JSON document into another. Paths in it are JSON Pointers such as /address/zip. Use it to send a change to an API that accepts application/json-patch+json, or to record a change compactly.
What happens if my JSON is invalid?
The tool names the line and column and says what's wrong, such as a trailing comma, single quotes, a comment or a missing comma, and shows that line with a caret under the problem. Fix it there, or tidy it first in the JSON Formatter.
How large a file can it compare?
Files up to 5 MB each, and up to 500,000 values on each side. Past that it says so instead of freezing the page; the changes list shows the first 1,000 differences, and Copy changes includes them all.
Is my JSON uploaded anywhere?
No. Reading, comparing and making the JSON Patch all happen in your browser. Nothing you paste or open is sent to a server, so API responses with tokens or customer data stay on your device.
About JSON Diff
Compare two API responses, config files or exported records in a text diff and half of what lights up isn't a change at all: the keys came back in a different order, or one file is pretty-printed and the other minified. JSON Diff compares what the documents mean instead. It reads both into data, matches keys by name and list items by position or id, and lists only the values that actually differ, each with its path.
Paths are written the way JSONPath tools write them: $.address.zip for a field in an object, $.items[2].price for a field in the third list item, $["first name"] for a key that isn't a plain word. Copy a path to find it in your code, or copy the whole list into a ticket or pull request.
The reader is strict JSON, so it catches the mistakes that break real parsers (trailing commas, single quotes, comments, leading zeros) and says exactly where they are. Numbers are compared from their exact digits, so 1.0 equals 1 but two long IDs that JavaScript would round to the same value stay different. All of it runs in your browser; nothing is uploaded.