JSON Array Comparator

Compares two JSON arrays by deep value equality and reports the results as three buckets: items only in A, items only in B, and items present in both, similar to a set difference and intersection over JSON values. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-24

Overview

Introduction

Sometimes the question isn't "what changed between these two arrays field by field" but simply "what's in one but not the other, and what do they share." That's a set comparison, not a positional diff.

This tool compares two JSON arrays as sets of items and reports the three natural buckets: only in A, only in B, and in both.

What Is JSON Array Comparator?

A comparison tool that parses two JSON arrays and, treating each as a collection of items rather than an ordered sequence, computes which items appear only in the first array, only in the second, or in both.

Equality between items is based on deep value comparison, so two structurally identical objects count as the same item even if they arrived in a different key order.

How JSON Array Comparator Works

Both inputs are parsed and confirmed to be JSON arrays. Each item in both arrays is converted to a canonical string form, recursively sorting object keys, so equality checks aren't thrown off by key ordering, then compared using that canonical string.

An item from A is placed in onlyInA if no item in B shares its canonical form, and symmetrically for onlyInB. Any item from A whose canonical form also exists in B is placed in inBoth. The result is returned as a single JSON object with those three array keys.

When To Use JSON Array Comparator

Use it to see what changed between two exported data snapshots when order doesn't matter, which records were added, which were removed, which are unchanged.

It's also useful for validating a migration or sync process: compare the source and destination arrays to confirm nothing unexpected was dropped or duplicated.

Features

Advantages

  • Deep equality means reordered object keys don't cause false mismatches.
  • Clear three-way output (onlyInA, onlyInB, inBoth) instead of a single flat list.
  • Reports parse or type errors per side, so you know exactly which input to fix.

Limitations

  • Ignores item order entirely; if you need an order-sensitive comparison, use JSON Diff instead.
  • Treats each occurrence independently rather than tracking exact counts, so it isn't a true multiset difference for arrays with repeated items.

Examples

Comparing two arrays

Input

A: [{"id":1},{"id":2}]
B: [{"id":2},{"id":3}]

Output

{
  "onlyInA": [{ "id": 1 }],
  "onlyInB": [{ "id": 3 }],
  "inBoth": [{ "id": 2 }]
}

Item id 1 is unique to A, id 3 is unique to B, and id 2 is shared by both.

Non-array input

Invalid input

A: {"id": 1}
B: [1, 2]

Parser error

A JSON: Top-level JSON value must be an array.

Side A is reported as the failing side since it's an object, not an array.

Corrected version

A: [{"id": 1}]

Best Practices & Notes

Best Practices

  • Use this over JSON Diff when you care about set membership (added/removed/shared items) rather than field-level changes at fixed positions.
  • If your arrays hold objects with a natural id, consider whether you actually want an id-based comparison; this tool compares whole items, so a changed non-id field makes an otherwise-matching item show up in both onlyInA and onlyInB instead of inBoth.
  • Pair with Merge JSON Arrays (with dedupe on) if, after comparing, you decide you want a single combined array.

Developer Notes

onlyInA and inBoth are computed by filtering A against a Set built from B's canonical forms (and vice versa for onlyInB), which keeps the comparison roughly linear in combined array size rather than the quadratic cost of a naive nested-loop pairwise comparison.

JSON Array Comparator Use Cases

  • Diffing two exported data snapshots to see what was added, removed, or kept
  • Validating a data migration by comparing source and destination arrays
  • Checking whether two API responses returned the same set of records

Common Mistakes

  • Expecting order-sensitive output; this tool intentionally ignores array order and only reports set membership.
  • Assuming duplicate items are deduplicated or counted; each occurrence is evaluated against the same membership test independently.

Tips

  • For a field-by-field, path-aware comparison instead of set membership, use JSON Diff.
  • Combine the onlyInA and onlyInB results manually if you need a single "everything that differs" list.

References

Frequently Asked Questions