· 5 min read
How to Compare Two JSON Objects Structurally
Heshan Fernando
Co-founder & COO
You’ve got two versions of a JSON object — an API response before and after a change, a config file across two environments, a saved state before and after some operation — and you need to know exactly what’s different between them. A plain text diff tool will show you every line that changed, but JSON’s key order isn’t semantically meaningful, so a text diff can show a wall of “changes” that are really just the same data serialized in a different order.
Comparing JSON structurally, rather than as plain text, means the comparison actually understands that {"a": 1, "b": 2} and {"b": 2, "a": 1} represent the same data — a distinction a text-based diff tool has no way to know.
What a structural JSON diff actually does
Rather than comparing line by line, a structural diff walks both JSON objects field by field, matching keys regardless of their order in the source text, and reports genuine differences: fields present in one but not the other (added or removed), and fields present in both but with different values (changed). This produces a much more useful comparison than a text diff for JSON specifically, since it filters out the noise of reordering and formatting differences that don’t represent any actual data change.
Color-coding added, removed, and changed fields separately makes the actual differences scannable at a glance, rather than requiring you to read through the full structure of both objects to spot what moved.
Why people get stuck here
- Text diffs flag reordering as a change. A plain text diff tool treats two semantically identical JSON objects with different key order as completely different, burying real changes in irrelevant noise.
- Nested structures are hard to compare by eye. JSON objects with nested objects or arrays are genuinely difficult to visually compare manually, especially past a shallow structure.
- Formatting differences (whitespace, indentation) obscuring real changes. Two JSON payloads with identical data but different formatting look completely different in a naive text comparison.
- Missing a small but important field difference. In a large object, a single changed value or a missing field can be easy to overlook when scanning by eye rather than using a tool that flags it explicitly.
What a good JSON diff tool looks like
Compares structurally, not as text
Matching keys and values regardless of order or formatting is the core requirement — anything less produces noise rather than a useful comparison.
Clearly categorizes each difference
Distinguishing added, removed, and changed fields with clear color-coding lets you scan a comparison quickly and understand the nature of each difference, not just that one exists.
Handles nested objects and arrays correctly
Since real-world JSON is rarely flat, the diff needs to recurse correctly into nested structures and report differences at the right level of nesting.
Common mistakes to avoid
- Using a plain text diff tool for JSON comparison, which flags harmless key reordering as if it were a meaningful change.
- Manually scanning two large or deeply nested JSON objects by eye, which reliably misses small but important differences.
- Ignoring type differences that a naive comparison might overlook — a value that’s the string “5” versus the number 5 are genuinely different in JSON even though they look similar.
- Comparing minified and pretty-printed versions of the same JSON without a structural tool, mistaking formatting differences for actual data changes.
- Not checking array order specifically — depending on the context, array element order can be meaningful and worth flagging differently than object key order.
How to do it with JSON Diff Tool
Online Tool Store’s JSON Diff Tool compares your JSON entirely in your browser.
- Open the JSON Diff Tool.
- Paste your two JSON objects.
- Review the structural comparison, with added, removed, and changed fields clearly color-coded.
- Use the categorized differences to understand exactly what changed between the two versions.
Because it compares structurally rather than as text, key reordering and formatting differences don’t create false positives in the comparison.
Frequently asked questions
Why does a text diff show so many changes when my JSON data barely changed?
A text diff compares line by line, so any difference in key order or formatting — even with identical underlying data — shows up as a change. A structural JSON diff instead compares the actual data values regardless of how they’re ordered or formatted in the source text.
Does a structural JSON diff care about array order?
This depends on the specific tool and context — in some cases array order is meaningful (a sequence of steps, for instance) and should be flagged if changed, while in other cases it isn’t. A good tool should handle this sensibly for your use case, and it’s worth checking how a specific tool treats array comparisons.
Can I use this to compare API responses from before and after a code change?
Yes — comparing two API response payloads structurally is a common and useful way to verify that a code change produced only the intended data differences, without unrelated fields accidentally changing.
Final thought
JSON’s key order doesn’t carry meaning, so a comparison that treats reordering as a change is comparing the wrong thing — a structural diff focuses on what actually matters: the data itself.