Skip to content

JSON Comparison Tool - Compare JSON Diffs Online

A free online JSON comparison tool that compares two JSON objects and lists every added, removed, and modified value, with the exact path to each change shown.

JSON Diff Tool

Loading calculator...
📚

Documentation

A JSON comparison tool, often called a JSON diff tool, compares two JSON (JavaScript Object Notation) values and reports what changed between them. It lists every property or array item that was added, removed, or modified, together with its exact location in the data. This page explains how the whiz.tools JSON comparison tool works, with worked examples based on its actual comparison logic.

What is JSON comparison?

JSON comparison is the process of checking two JSON documents against each other to find differences. A JSON document is a piece of text built from objects (key-value pairs in curly braces), arrays (ordered lists in square brackets), and primitive values such as strings, numbers, booleans, and null. Comparing two of these documents by eye is slow and error-prone once they grow past a few lines, so a comparison tool does the matching automatically and highlights each change.

Developers use this kind of comparison to check API responses, track changes in configuration files, verify that a data migration did not lose information, and review changes to JSON files in version control.

How the tool compares two JSON values

The tool parses both inputs with a standard JSON parser, then walks through the two resulting values together, one level at a time. At each step it asks three questions, in order:

  1. Do the two values have different types (for example, one is an object and the other is a number), or is one null while the other is not? If so, it records a modification at that spot and stops comparing deeper.
  2. Are both values primitives (a string, number, boolean, or null)? If so, it compares them directly. Any difference, including a change from the number 123 to the string "123", counts as a modification.
  3. Are both values objects or both arrays? If so, it compares their contents using the rules below, and recurses into any nested objects or arrays.

Every difference is recorded with a path, such as user.address.city or tags[1], so it is easy to find in the original document.

Comparing objects

For two JSON objects, the tool collects every key that appears in either object. For each key:

  • If the key exists only in the second object, that is an added property.
  • If the key exists only in the first object, that is a removed property.
  • If the key exists in both, the tool compares the two values recursively.

Key order does not matter. The JSON standard does not define an order for object members, so {"a":1,"b":2} and {"b":2,"a":1} are treated as identical.

Comparing arrays

Arrays are compared by position, not by content. The tool steps through both arrays index by index and compares whatever sits at each index, up to the length of the longer array. If one array is shorter, the extra items at the end of the longer array are reported as added or removed.

This means the tool never tries to match array items by their content. It does not notice that an object was "moved" from index 1 to index 2; it only sees that the value at each index changed. Deleting or inserting an item in the middle of an array shifts every following item over by one position, so it usually shows up as several separate modifications rather than one clean addition or removal.

Worked examples

Example 1: comparing two objects

First JSON:

1{ "user": { "address": { "city": "New York", "zip": "10001" } } }
2

Second JSON:

1{ "user": { "address": { "city": "Boston", "zip": "02108" } } }
2

Result:

  • Modified user.address.city: "New York""Boston"
  • Modified user.address.zip: "10001""02108"

Example 2: an array change at the end

First JSON:

1{ "tags": ["important", "urgent", "review"] }
2

Second JSON:

1{ "tags": ["important", "critical", "review", "documentation"] }
2

Index 0 is unchanged, index 1 changed, index 2 is unchanged, and index 3 only exists in the second array. Result:

  • Modified tags[1]: "urgent""critical"
  • Added tags[3]: "documentation"

Example 3: removing an item from the middle of an array

This example shows what happens when an item is removed from the middle of an array, because it is a common source of confusion.

First JSON:

1{
2  "products": [
3    { "id": 1, "name": "Laptop", "price": 999.99 },
4    { "id": 2, "name": "Mouse", "price": 24.99 },
5    { "id": 3, "name": "Keyboard", "price": 59.99 }
6  ]
7}
8

Second JSON, with the "Mouse" entry deleted and a "Monitor" entry added at the end:

1{
2  "products": [
3    { "id": 1, "name": "Laptop", "price": 899.99 },
4    { "id": 3, "name": "Keyboard", "price": 59.99 },
5    { "id": 4, "name": "Monitor", "price": 349.99 }
6  ]
7}
8

A person looking at this would say "Mouse was removed and Monitor was added." Because the tool compares strictly by index, it does not see it that way. It compares index 0 to index 0, index 1 to index 1, and index 2 to index 2, so every field after the deleted item lines up against the wrong object. The actual result is seven modifications:

  • Modified products[0].price: 999.99899.99
  • Modified products[1].id: 23
  • Modified products[1].name: "Mouse""Keyboard"
  • Modified products[1].price: 24.9959.99
  • Modified products[2].id: 34
  • Modified products[2].name: "Keyboard""Monitor"
  • Modified products[2].price: 59.99349.99

To get a cleaner result when comparing lists like this, sort or key both arrays the same way before pasting them in, for example by writing each list in the same order or matching objects by an ID field before comparison.

What the tool does not do

  • It does not match array items by content. As shown above, it compares purely by index position, so it cannot recognize that an item moved rather than changed.
  • It does not detect circular references. This is not a limitation in practice: both inputs come from JSON.parse, which always builds a plain tree and can never produce a value that refers back to itself. Circular references cannot exist in valid JSON text in the first place.
  • It does not offer a setting to sort arrays before comparing. Reordering the items in your input before pasting them is the only way to avoid the index-shift effect described above.

How to use the tool

  1. Paste the first JSON document into the left box and the second into the right box.
  2. The tool compares them automatically once both boxes contain text, or click Compare to run it manually.
  3. Read the results list. Each line shows a path, such as user.age, and whether it was added, removed, or modified, with the old and new values shown side by side.
  4. Click Copy to copy the results as plain text.

If either box contains text that is not valid JSON, the tool shows an error for that box instead of a comparison.

Frequently asked questions

What counts as a difference between two JSON values? A property or array item is different if it exists in only one of the two documents, or if it exists in both but holds a different value or a different type. Changing a value from the number 5 to the string "5" counts as a modification, even though they may look similar.

Does the order of object properties matter? No. JSON objects have no defined member order, so two objects with the same keys and values in a different order are treated as identical.

Does the order of array items matter? Yes. Arrays are compared by index position, so moving an item to a different position in the array is treated as a series of modifications, not as a move.

Is my JSON data sent to a server? No. The comparison runs in the browser using JavaScript. Nothing is uploaded.

Does formatting, such as indentation or minification, affect the result? No. Both inputs are parsed into JSON values before comparison, so whitespace, indentation, and line breaks make no difference. Only the actual data is compared.

Can the tool compare JSON with comments or trailing commas? No. Standard JSON, as defined in RFC 8259, does not allow comments or trailing commas. Input containing them is rejected as invalid.

References

  1. IETF. "The JavaScript Object Notation (JSON) Data Interchange Format." RFC 8259, December 2017.
  2. IETF. "JavaScript Object Notation (JSON) Patch." RFC 6902, April 2013.
  3. Mozilla Developer Network. "JSON.parse()."