jsontoolskit.org
JSON and JSON Schema utilities, in the browser
Say hi →

JSON Array Set Operations

union · intersection · A − B · B − A · symmetric difference

Two arrays and one question: what is in both, what is only in one. Comparison uses RFC 8785 canonical form, so two objects that differ only in key order count as the same element — which naive comparison gets wrong and is the reason set operations on JSON so often produce nonsense. Or name a key field and match on identity alone.

Paste both arrays to start.

How to compare two JSON arrays

  1. Paste an array in each pane. Both must be arrays at the top level.
  2. Pick the operation. The status bar always reports all three counts — in both, only in A, only in B — whichever one you chose, so a single run answers the whole question.
  3. Leave the key field blank to match whole elements, or name one or more fields to match on identity.
  4. Copy or download the result. Output elements are the originals, unchanged; A's version wins where both sides have a match.

Whole value versus key field

With the key blank, two elements are equal only if their canonical forms match — every key, every value, key order and whitespace ignored. That is the right test for "did this list change", and it means a record that differs by one character appears in both only in A and only in B. That is not a bug: by whole-value comparison they genuinely are different elements.

Name a key and the comparison uses only that field, so a record whose address changed is "in both". This is the mode for reconciling two exports of the same entities. To see what changed rather than which side an element is on, use Diff.

Which operation answers which question

A ∩ B — already exists, already processed, the overlap between two audiences. A − B — new since last time, still to do, removed. B − A — the same question from the other side, which is what you want when B is the newer file and you are looking for additions. A ∪ B — one combined list with each element once. A + B — plain concatenation with duplicates preserved, for when the counts matter. A △ B — everything not in both, the quickest way to see the full extent of a divergence.

Every operation except concatenate deduplicates its own output, so if A itself contains the same element twice, the union has it once. Use Dedupe array first if you want to know how many repeats each side had before comparing.

Privacy

Nothing is uploaded. Both arrays are compared in this tab using your own browser's JavaScript engine — no server sees your data, and the page keeps working with the network disconnected.

FAQ

Do the two arrays need the same shape?

For whole-value comparison, effectively yes — different shapes never match. For key comparison the field is resolved on each side independently, so the arrays only have to agree about the key. Output elements keep whatever shape they had.

Why is my intersection empty?

Usually a type mismatch — "1" and 1 are different values in JSON and will never match. Check with a key-field comparison, which stringifies before comparing, or normalise the types first. Whitespace inside string values is another common cause; the case checkbox handles capitalisation but not padding.

Is 1 the same as 1.0?

Yes — canonicalisation puts numbers in their shortest round-trip form, so both become 1. A number and the string "1" stay different, which is correct.

Can I compare more than two arrays?

One pair at a time: run A against B, paste the result back into pane A, and run it against C. Each pass is independent, so you can change the key between passes.