How to Compare JSON Objects

A line diff is useful for source files, but JSON responses often reorder object keys or change indentation without changing the data. A structural comparison highlights value changes. Decide how your application interprets array order and absent fields before you use the result as a regression signal.

Compare two fixture revisions

Paste the first document as Original and the second as Updated. The change to active appears at /feature/active, and sampleRate is an addition. The key order is irrelevant. A structural comparison keeps a formatting-only save from overwhelming the review.

The path uses JSON Pointer. A slash separates segments, while ~1 represents a slash inside a property name and ~0 represents a literal tilde. When reporting a difference, include both the path and the direction so the reader knows which fixture contains the field.

JSON documents (before, then after)
{"feature":{"active":false,"scope":"team"}}
{"feature":{"scope":"team","active":true,"sampleRate":0.25}}
Result
Changed /feature/active: false → true
Added /feature/sampleRate: 0.25

Decide whether indexes or keys define identity

A positional comparison treats array elements as ordered. Inserting a new record at the front can make every later index appear changed. If your API defines order as significant, such as search rank or pipeline steps, preserve it and examine those changes.

If an array represents a set of records with stable IDs, compare copies sorted by ID, or index the records by ID before comparing. Check for duplicates first because an object keyed by a repeated ID can overwrite data. Use a consistent ordering that matches the identifier type and keep the original fixture for debugging.

Distinguish absence from a present value

An omitted property and one set to null have different meanings in many APIs. An omitted field may leave a value unchanged in a patch while null clears it. Compare exact types as well: the string 2 and number 2 are distinct. For large numeric identifiers, use strings so two different IDs are not rounded to the same JavaScript number.

Before drawing conclusions, validate both documents. Keep a raw copy when duplicate keys or precision seem relevant because the parser may have normalized those details before comparison.

Frequently asked questions

Does it ignore whitespace inside a string?
Whitespace inside a string is part of the value. Formatting around JSON tokens can be ignored without changing that string.
Why is a full new object shown as one addition?
Reporting its path once keeps the change list readable. Inspect the added value to see the nested fields it contains.

Try it with these tools

Related developer guides