Compare two JSON arrays by id

Compare two lists of JSON objects by id and see which items changed, moved, were inserted or were deleted.

API responses, database exports and config files often hold a list of objects that each carry an id, and the same list can come back in a different order. A plain diff reads that as a wall of changes, because position 0 is compared with position 0. This page opens with Match array items by key switched on, so each object is paired with the object that has the same id, and the list shows only what really differs: a field that changed, such as /users[id=1]/role from admin to owner, an item that was deleted, an item that was inserted, and an item that moved to another place. It looks for id, _id, key and uuid on every item, or you can type a key such as sku. The sample shows all four kinds in a three user list. One honest limit: ids must be unique within a list and present on every object, otherwise that list is compared by position and the page tells you so.

How it works

  1. Paste the original JSON and the changed JSON
  2. Choose whether array order and letter case matter
  3. Read the change list or copy the JSON Patch

Frequently asked questions

Why is an item moved when only its index changed?

A move is reported when an item's place among the other matched items changed. In [1,2,3] against [2,3] the ids 2 and 3 only shift up one index after 1 is deleted, so just the deletion is listed. Swapping ids 1 and 2 reports one move.

Does the patch handle moved items?

Yes. With a key, the JSON Patch removes deleted items, adds inserted ones at their index and uses RFC 6902 move operations, so applying it to the original gives the changed list in the same order. With Ignore array order on, it only appends new items.

Can I match on a key that is not id?

Yes. Type the name in Key to match on, for example sku, email or slug. The values must be strings or numbers, present on every object and different from each other in both lists, and 1 and "1" count as different values.