JSON Diff
Compare two JSON documents structurally, so key order and indentation are ignored. Match array elements by id, and export the result as a JSON Patch.
Compare two JSON documents as structures rather than as text. Differences in key order and indentation are ignored, so only values that genuinely changed are reported. Array elements can be matched by an id field, and the result exports as an RFC 6902 JSON Patch.
💡 Differences in key order and indentation are not reported. Only values that actually changed appear here.
// JSON Diff: Features
Why a textual diff is the wrong tool for JSON
A text diff compares characters, so two documents with identical content but different key order report as entirely different. The same happens when one file uses two-space indentation and the other uses four. This tool parses both sides and walks the resulting structures, so those presentational differences disappear and what remains is the set of values that actually changed. For comparing plain text, the Diff Checker is the right tool.
Four kinds of difference, kept separate
Added means a key or element exists only in B; removed means only in A; changed means the same type with a different value; and type changed means the type itself moved, as when the number 3 becomes the string "3". That last category matters more than it appears. A value that quietly changes from number to string still parses, still renders, and then fails a schema validation or a strict comparison somewhere far from where it was introduced. An ordinary diff shows it as a change like any other.
Why an array diff explodes, and how to stop it
Arrays can be compared by position or by a key field. Comparing by position is correct when order carries meaning, such as a list of steps. It is wrong for anything an API returns in an unspecified order: insert one element at the front and every subsequent position reports as different, burying the one real change in noise. Matching by id pairs elements up regardless of where they sit, so reordering produces no diff at all and a genuine change stands out.
What a JSON Patch (RFC 6902) is for
The difference can be emitted as a JSON Patch: a list of add, remove and replace operations that transforms A into B. It is an IETF standard with library support in most languages, which means the output is not merely something to read but something to apply. Use it to build the body of a PATCH request, to script a configuration change, or to record precisely what moved between two deployments. Paths are available in dot notation for reading and JSON Pointer for machines.
Safe to compare production responses
Parsing and comparison both run as JavaScript in your browser, and neither document is transmitted, stored or logged. That matters because the documents most worth comparing are often the ones you cannot upload: an API response containing personal data, a configuration file with credentials, the difference between production and staging. To tidy a document before comparing it, the JSON Formatter handles indentation; to locate a value by path, use the JSONPath Finder.
// JSON Diff: FAQ
Does a different key order count as a difference?
- No. Both sides are parsed and compared as structures, so the order in which keys appear is irrelevant. Two objects with the same keys and values report as identical however they are written, and indentation and line breaks are ignored for the same reason. This is the main practical difference from a text diff.
What does "type changed" mean?
- The type of the value itself moved, for example from the number 2 to the string "3". It is reported separately from an ordinary value change because the consequences are different: the document still parses, but schema validation, strict equality and arithmetic all behave differently afterwards. It is a common way for a working system to break quietly after an API change.
When should I match arrays by key rather than by position?
- Match by key whenever the order is not part of the meaning, which covers most collections returned by an API. Compare by position when order matters, such as a sequence of steps or a time-ordered log. The symptom of the wrong choice is obvious: one inserted element makes every later position report as changed.
What happens to array elements without the match key?
- They fall back to positional comparison. An array mixing objects that have the key with primitives that cannot will still produce a result, but a mixed array is ambiguous by design, and normalising the data is usually better than relying on the fallback.
Can I apply the JSON Patch directly?
- The output follows RFC 6902, with op, path and value fields, so any conforming library will apply it. Be aware that add and remove against array indices are interpreted differently by some implementations, so test a patch that touches arrays before relying on it in an automated flow.
What is the difference between dot notation and JSON Pointer?
- Dot notation, such as $.users[0].name, is easier to read and close to JSONPath. JSON Pointer, such as /users/0/name, is the RFC 6901 standard and is what JSON Patch uses. Choose dot notation when a person will read the result and JSON Pointer when a machine will.
How large can the two documents be?
- A few thousand lines per side is comfortable. Every element is walked recursively and every difference rendered, so documents of tens of thousands of lines will feel slow. For files that large, extracting the subtree you care about, or using a command line tool such as jq, is more practical.
The diff is too long to read. What should I do?
- Switch arrays to key matching first: a single inserted element shifting every position is the most common cause of an unreadable diff. If it is still long, compare a subtree rather than the whole document, which also makes the result easier to explain to someone else.
What happens if one side is not valid JSON?
- The parse error is reported under the side that failed, so you know which document to fix, and the message includes the position where the parser stopped. Trailing commas, single quotes and comments are the usual causes, since none of them are valid JSON.
Are the two documents sent to a server?
- No. Parsing and comparison run entirely in your browser, and neither document is transmitted, stored or logged. You can confirm it in the network tab of your developer tools.
// How to Use JSON Diff
-
Paste both documents
Put the original into the left box and the version you are comparing against into the right. The sample button loads an example containing reordered keys, a type change and a reordered array, which shows what the tool does and does not report.
-
Choose how arrays are compared
Use positional comparison when order carries meaning, and key matching for collections whose order is not guaranteed. When matching by key, name the field that identifies an element, usually id.
-
Read the differences, or take the patch
Additions, removals, value changes and type changes are listed separately and colour-coded. Switch to the JSON Patch view for an RFC 6902 operation list that turns A into B, ready to paste into a PATCH request or an apply script.
Category Data Formats