How to Compare Two JSON Files and Spot Real Differences

Why a line-by-line diff misleads for JSON, how a semantic JSON diff works, when to ignore array order, and how to compare JSON with jq, Node.js or a browser.

Updated September 29, 2026 6 min read

Use the free JSON CompareDiff two JSON documents path by path, ignoring object key order

Yesterday's API response worked; today's breaks the front end. A config file was regenerated by a tool and your version-control diff shows 300 changed lines. A customer record was exported from two systems and they swear it is identical. In each case you do not care about spacing or key order; you want to know which values actually changed.

This guide explains why an ordinary text diff is a poor fit for JSON, how a structural (semantic) comparison works, the tricky question of array order, and several ways to compare JSON documents: in the browser, with command-line tools and in code.

Why a text diff is the wrong tool

Text diff tools compare lines. JSON documents that mean the same thing can look very different line by line:

  • Formatting. One file is minified, the other indented with four spaces. Every line differs.
  • Key order. {"id": 1, "plan": "pro"} and {"plan": "pro", "id": 1} are equal JSON objects. RFC 8259 describes objects as unordered collections of name/value pairs, and many serialisers do not preserve order.
  • Moved blocks. A reordered section shows up as a large deletion and a large insertion.

A text diff is still the right tool when you care about the file itself, such as reviewing formatting changes in a pull request. For those cases the Text Diff tool is a better match. When you care about the data, you want a structural comparison.

How a semantic JSON diff works

A structural diff parses both documents and walks them together:

  1. Objects are compared key by key, regardless of order. A key only on the left is removed; a key only on the right is added; a key on both sides is compared recursively.
  2. Arrays are compared position by position: item 0 with item 0, item 1 with item 1, and so on. Extra items at the end are added or removed.
  3. Primitive values are compared directly. If the type changed, for example the number 5 became the string "5", that is reported separately from an ordinary value change, because it is usually a bug rather than an update.

Each difference is reported with a path, such as $.address.zip or $.lines[0].qty, so you can find it in either file immediately.

The array order question

Consider two versions of an order:

{ "tags": ["vip", "eu"], "lines": [{ "sku": "A", "qty": 1 }, { "sku": "B", "qty": 2 }] }
{ "tags": ["eu", "vip"], "lines": [{ "sku": "B", "qty": 2 }] }

Compared by position, tags[0] changed from "vip" to "eu" and tags[1] from "eu" to "vip". The first line item appears to have its sku and qty changed, and lines[1] appears removed. Technically correct, but misleading: really, line A was removed.

Compared as unordered collections, tags is unchanged and the report says simply that {"sku": "A", "qty": 1} was removed.

Which is right depends on the meaning. For tags, permissions or a set of IDs, order is usually irrelevant, so ignore it. For steps in a workflow, ranked search results or chart data points, order is the data, so keep positional comparison.

Compare JSON with our tool

The JSON Compare tool performs the structural comparison described above, entirely in your browser.

  1. Open JSON Compare. Paste the older version into Original JSON and the newer one into Modified JSON. Load sample fills both sides with an example.
  2. Object key order is always ignored. Switch on Ignore array order if your arrays are sets rather than sequences.
  3. Read the summary badges: counts of added, removed, changed and type changed entries.
  4. Scan the list. Each row shows its kind, the JSONPath-style path, and the old and new values. If the documents are the same, you see "The two JSON documents are equivalent."
  5. Click Copy report to get a plain-text summary, one line per difference, for a ticket or pull request. Use Swap sides if you pasted them the wrong way round.

If either side is not valid JSON, the tool shows the error with its location. Fix it first, or check it in the JSON Validator.

Other ways to compare JSON

jq plus diff

Normalise both files with sorted keys, then use an ordinary diff. In Bash:

diff <(jq -S . before.json) <(jq -S . after.json)

This removes formatting and key-order noise. It does not ignore array order, and the output is line-based rather than path-based, but it is quick and scriptable.

In Node.js tests

For a yes-or-no answer in a test, Node's built-in deep equality ignores object key order but treats array order and types strictly:

const { isDeepStrictEqual } = require("node:util");

isDeepStrictEqual({ a: 1, b: [1, 2] }, { b: [1, 2], a: 1 }); // true
isDeepStrictEqual({ a: [1, 2] }, { a: [2, 1] });             // false
isDeepStrictEqual({ n: 5 }, { n: "5" });                      // false

Test frameworks show a structural diff when such an assertion fails, which is often enough during development.

Editors and IDEs

Most editors can diff two files side by side. Format both with the same settings first (for example with the JSON Formatter and sorted keys) to cut the noise.

Tips for reading JSON diffs

Look at type changes first

A value that became a string, or an object that became null, breaks code more often than a changed value. Serialisers that switch between 5 and "5" are a common cause of front-end bugs.

Large documents

If a diff reports hundreds of changes, look for a pattern: a renamed key produces one removed and one added entry for each object that has it. Once you spot a rename, the rest of the report shrinks mentally to a single change.

Arrays of records with IDs

When items have stable IDs, sort both arrays by ID before comparing, or compare with array order ignored. Otherwise an insertion near the top shifts every following position and every item looks changed.

Focus on one branch

For a big payload, extract the part you care about first, for example $.data.items, with the JSONPath Tester, then compare only that.

Frequently asked questions

Does JSON key order matter?

Not for meaning. JSON objects are unordered, so two objects with the same keys and values are equal regardless of order. Some tools preserve order for readability, but code should not rely on it.

How do I compare JSON while ignoring array order?

Use a comparison that treats arrays as multisets, like the Ignore array order option, or sort both arrays in a consistent way before comparing.

What is the difference between changed and type changed?

"Changed" means the value is different but the type is the same, for example "pro" to "business". "Type changed" means the kind of value changed, such as a number becoming a string.

Can I compare very large JSON files in the browser?

Files of several megabytes are generally fine, since everything runs locally. Very large exports are more comfortable with command-line tools such as jq.

Why does my diff show every line changed?

You are probably using a text diff on files with different formatting or key order. Normalise both with sorted keys and the same indentation, or use a structural JSON comparison.

Try it now: JSON Compare

Loading tool…