User Rating 0.0
Total Usage 0 times
Category JSON Tools
0 chars
0 chars
Is this tool helpful?

Your feedback helps us improve.

About

Comparing JSON arrays by visual inspection fails beyond a few dozen elements. Missed differences in API responses, database exports, or configuration files cause silent data corruption and downstream bugs that surface days later. This tool performs recursive structural comparison of two JSON arrays. It matches elements by detected primary key (id, _id, key) when present, falling back to positional index comparison. Each nested object, array, and primitive is diffed to the leaf level. Results classify every element as added, removed, modified, or unchanged with exact path reporting.

The comparison engine handles type mismatches (NULL vs. string, number vs. boolean), nested depth up to 50 levels, and arrays of mixed types. Note: for arrays without identifiable keys, element reordering is reported as modification rather than movement. Approximate time complexity is O(n d) where n is element count and d is average nesting depth.

json compare json diff array comparison json array diff deep compare json json merge tool json difference checker

Formulas

The comparison produces a diff tree. Each node carries a status flag derived from structural analysis:

diff(a, b)
{
UNCHANGED if deepEqual(a, b) = TRUEADDED if a = UNDEFINEDREMOVED if b = UNDEFINEDMODIFIED otherwise

Where a is the element from Array A and b is the matched element from Array B. Key-based matching resolves b by searching Array B for an object whose primary key value equals that of a. The primary key is auto-detected by scanning the first element of each array for common identifier fields: id, _id, key, uuid, name.

The deep equality function recurses with a maximum depth of 50:

deepEqual(x, y) = type(x) = type(y) keys(x) = keys(y) k keys deepEqual(x[k], y[k])

Statistics are computed as a single pass over the diff tree:

Stotal = Sadded + Sremoved + Smodified + Sunchanged

Where each S is a count of top-level array elements classified by their diff status.

Reference Data

ScenarioDetectionMatching StrategyExample
Element added to Array BAddedKey or index absent in A{"id":5} exists only in B
Element removed from Array ARemovedKey or index absent in B{"id":3} exists only in A
Primitive value changedModifiedSame key/index, different value"name":"Alice""name":"Bob"
Type changedModifiedSame path, different JSON type"age":25"age":"25"
Nested object changedModified (deep)Recursive key comparison"address.city" differs
Nested array length differsModified + Added/RemovedIndex-based sub-diff"tags":[1,2]"tags":[1,2,3]
Element identicalUnchangedDeep equality checkAll keys and values match recursively
Null vs. missing keyModifiedExplicit null ≠ absent key"x":null vs. key absent
Empty object vs. populatedModifiedKey count differs{} vs. {"a":1}
Array of primitivesPer-indexIndex-based comparison[1,2,3] vs. [1,4,3]
Mixed types in arrayPer-index + type checkIndex-based with type annotation[1,"a",true] vs. [1,"b",false]
Large arrays (>1000 elements)Full diffKey-match preferred for performanceAPI response comparison
Duplicate keys in objectsLast-value-wins (JSON spec)Standard JSON.parse behaviorPer RFC 8259
Unicode stringsExact matchCode-point comparison"caf\u00e9" vs. "café"
Number precisionStrict equalityIEEE 754 double comparison0.1+0.20.3

Frequently Asked Questions

The tool first attempts key-based matching. It scans the first object in each array for common identifier fields (id, _id, key, uuid, name). If a shared key is found, elements are matched by key value regardless of position. If no key is detected, comparison falls back to index-based matching: element at index 0 in Array A is compared to index 0 in Array B. Extra elements in the longer array are classified as added or removed.
With key-based matching enabled (when objects contain an id-like field), reordering does NOT produce false modifications. Each element is matched by its key value. Without a detectable key, index-based comparison treats reordering as modification because element at index N in Array A is compared to the element at the same index N in Array B.
The tool recurses up to 50 levels deep. For modified elements, it reports the exact JSON path where the difference occurs (e.g., address.city or tags[2]). Each nested difference is color-coded and indented to reflect its depth in the object tree.
The tool uses strict JavaScript equality (===) for number comparison. Since IEEE 754 defines 0.1 + 0.2 as 0.30000000000000004, it will NOT equal 0.3 and will be flagged as modified. This is intentional - the tool reports what JSON.parse produces, which is the exact numeric representation.
Yes. Each element is compared based on its JSON type. If Array A has a string at index 2 and Array B has an object at index 2, the tool reports a type mismatch modification. The diff output shows both the old type/value and new type/value for clarity.
The tool runs entirely in the browser. Practical limits depend on available RAM. Arrays up to approximately 10,000 elements with moderate nesting (5-10 levels) process in under 2 seconds on modern hardware. Beyond 50,000 elements, expect noticeable delay. The tool shows a progress indicator for comparisons exceeding 200ms.
They are treated as different. An object {"x": null} has the key x with an explicit null value. An object {} does not have the key x at all. Comparing these two objects will report key x as removed (present in A, absent in B) or added (absent in A, present in B), not as unchanged.