Compare JSON while ignoring object key order
Two JSON objects can be equivalent even when their properties appear in a different order. A raw text diff treats that harmless reordering as a change; a semantic diff does not.
Objects and arrays follow different rules
Object property order is not semantically meaningful, so properties should be matched by name. Array order usually is meaningful, so values should remain tied to their index unless the application defines a separate identity rule.
Flatten values into stable paths
Paths such as $.customer.address.city or $.items[2].price provide a stable coordinate for every primitive value. Comparing those coordinates reveals additions, removals, and value changes without noise from indentation or key order. For example, {"name":"Ada","role":"analyst"} and {"role":"analyst","name":"Ada","active":true} share the first two paths and add $.active. Text files loaded from disk are limited to 10 MB and the displayed result is capped at 10,000 differences.
- Parse both documents first.
- Sort object keys deterministically.
- Preserve array indexes.
- Compare the value at each resulting path.
Know when preprocessing is required
Generated timestamps, request IDs, and unordered arrays may need an explicit ignore or sorting rule. Apply those rules before comparison and document them; otherwise the result cannot be reproduced.