How to Compare Two JSON or API Responses
8 min read
"Why is staging returning something different from production?" is one of the most common debugging questions there is, and the answer is almost always hiding in a small difference between two JSON payloads. Spotting that difference by eye is miserable β the documents are long, the keys may be in a different order, and the one field that changed is buried. This guide gives you a dependable workflow for comparing two JSON documents and reading the result.
Why eyeballing fails
JSON objects are formally unordered, so two responses that are semantically identical can serialise their keys in different orders. A naive text diff then lights up every line, even though nothing meaningful changed. On top of that, real payloads contain noise β timestamps, request ids, signed URLs β that differs on every call and drowns out the field you actually care about. A good comparison workflow deals with both problems.
Step 1: Normalise both sides
Before comparing, put both documents into the same canonical form: pretty-print them with the same indentation and, ideally, sort object keys. Once both sides are formatted identically, a line-based diff becomes meaningful instead of noisy. Paste each payload into a panel of the JSON Wallet editor and format them so you are comparing like with like.
Step 2: Strip the noise
Remove or blank out fields you know will always differ and do not care about β requestId, timestamp, traceId, ephemeral tokens. You can delete them in the editor, or use a query tool to project only the fields that matter. For example, with jq:
# keep only the fields you want to compare
jq '{ id, status, items }' response-a.json > a.json
jq '{ id, status, items }' response-b.json > b.jsonStep 3: Diff and read the result
With both sides normalised, run a comparison. JSON Wallet's Compare mode shows a line-by-line diff of the two panels, highlighting additions, removals and changes. Read it structurally rather than character by character: a removed line plus an added line at the same position is a changed value; a lone added line is a new field; a lone removed line is a missing one.
Understanding the kinds of differences
- Value change: same key, different value β the most common and usually the one you are hunting.
- Missing/extra key: one side has a field the other lacks, often a versioning or feature-flag difference.
- Type change: a field is a number on one side and a string on the other β a frequent source of client bugs.
- Array order: arrays are ordered, so
[1, 2]and[2, 1]genuinely differ. If order should not matter, sort both arrays before comparing.
Comparing programmatically
When you need this in a test or a script rather than by hand, compare parsed structures instead of raw text so key order never matters:
// JavaScript: order-independent deep compare
import { isDeepStrictEqual } from "node:util";
const equal = isDeepStrictEqual(JSON.parse(a), JSON.parse(b));For a machine-readable description of what changed (not just whether it did), JSON Patch (RFC 6902) expresses the difference as a list of add/remove/ replace operations β useful for audit logs and for applying the same change elsewhere.
Frequently asked questions
Why does my diff show changes when the data looks identical?
Almost always key order or whitespace. Format and sort both documents first, then diff β the spurious differences disappear and only real changes remain.
Should array order count as a difference?
It depends on your data. JSON arrays are ordered, so by default a reordered array is a real difference. If order is not significant in your case, sort both arrays before comparing.
Is it safe to compare production payloads in a browser tool?
In JSON Wallet, yes β comparison runs entirely in your browser and nothing is uploaded, so you can diff responses that contain tokens or customer data. See our Privacy Policy.
Next steps
To pull just the fields you want to compare, see querying JSON with JSONPath or the jq playground. If a payload will not parse in the first place, start with common JSON errors.
Primary references
This guide is checked against the specifications and runtime documentation below. Examples are also run through JSON Wallet before publication.
Keep reading
What Is JSON? A Beginnerβs Guide
JSON is the most widely used data format on the web. This guide explains what it is, how it is structured, and where you will run into it as a developer.
JSON Syntax Rules Explained (With Examples)
JSON has a small but strict grammar. This reference walks through every rule with valid and invalid examples so your data parses the first time.
Common JSON Errors and How to Fix Them
Every developer hits "Unexpected token in JSON" eventually. Here are the most common JSON errors, what causes them, and exactly how to fix each one.
Ready to put this into practice? Open the free JSON editor β