How to compare two API responses and find the difference
Two windows of JSON side by side and hunting for the difference by eye — that’s half an hour gone, and the field that became a string still gets lost among changed prices. In Microkoi Bench the difference between two responses opens with the C key: what changed type, what disappeared, what appeared, and separately, which values differ.
When you need a comparison
- Yesterday the restaurant menu screen opened, today it crashes. What changed in the response?
- Everything works on the stand, but not for users in production. How do the responses differ?
- A request with a promo code returned a different total. Which fields changed?
A line-by-line diff of two JSON documents hundreds of lines long is almost useless: different IDs, different times, a different field order. What matters — a change in the response model — drowns in the noise of values.
Compare with the previous response in one keystroke
Select an exchange in Traffic and press Shift+C or choose “Compare with previous” in the row menu. Bench finds an earlier response of the same endpoint — same host, method, status code and path, give or take IDs like /v1/{id} — and opens the comparison in place of the exchange panel. The earlier response is on the left.
Or pick any two exchanges
- Select the first exchange and press C — or choose “Compare with…” in the row menu.
- A “Pick an exchange to compare with #1283” bar appears above the table, and the row gets the letter A.
- Move to the second exchange with the arrow keys and press Enter, or just click it.
If both exchanges are in view, select them — click the first and ⌘-click (Ctrl-click) the second — and press C. “Swap” in the comparison header switches A and B.
Three comparison tabs
| Tab | What it shows |
|---|---|
| “Structure” | Fields that changed type, disappeared, appeared or became null, with the path and the A and B values |
| “Body” | Bodies line by line in two columns; field order and whitespace don’t count as differences |
| “Headers” | Status code and headers; Date, X-Request-Id and the like are hidden |
The number on a tab is how many differences it has, and the first tab with differences opens. If the responses are identical, Bench says so: “Responses match”.
On the “Body” tab, the lines of a field that changed type are highlighted yellow on both sides, and the tooltip names the change: “type: number → string”. The “Model changes only” toggle dims the lines where only values changed. Out of a hundred red and green lines, the five places you opened the comparison for remain. JSON the server sent as a string is shown expanded with a “~ JSON in string” tag, and a change inside it is marked on the line of the field itself, not the whole long string.
Send the difference to a ticket
- The copy icon copies the difference on the open tab as text — handy to paste into a ticket for the backend.
- “Export to HTML” saves the comparison as one file with all three sections. It opens in a browser without Bench.
- The “Types only” option leaves body and header values out of the file — only field names, types and status codes.
The stand and production answer differently
If the app talked to both the stand and production, Bench compares the contracts of one endpoint across hosts on its own: field types, null, fields that come from only one host. Values and status codes aren’t compared — environments legitimately differ in data.
A method that answers differently on another host is marked in the endpoint tree with blue framed braces. Select it, and a “Hosts respond differently” bar appears above the table: each field and how it looks here and there. For example, amount is a string on api.stage.example.com and a number on api.example.com. “Compare” in the bar opens the two latest responses side by side.
The whole difference between two environments at once
- In the endpoint tree, open the “⋯” menu on the stand host.
- Choose “Compare contracts with host…” and pick the production host.
- The “Host contracts” summary opens in place of the exchange panel.
The summary gives a one-line verdict, such as “Respond differently: 1 of 5 shared endpoints.”, and groups: what responds differently, what exists on only one host, where there are still too few responses to compare. “Export to HTML” saves the whole summary as one file.
Host comparison is built from recorded traffic. To check stands on a schedule, not only when the app happened to go there, use monitoring.
What you get
Answering “what changed” takes seconds. A model change doesn’t get lost among values, and the backend gets the difference as text or a file, not a screenshot of two windows.
Compare the next odd response with the previous one in beta 0.9.6 and write to beta@microkoi.com about what the comparison lacked. We read every email.