Pack Camo

JSON Diff: Compare Two JSON Documents

Porównaj dwa dokumenty JSON według struktury, a nie wierszy. Wszystko działa lokalnie — nic nie jest wysyłane.

Wejście
Two JSON documents
Wyjście
Path-level changes · JSON Patch

Original

valid

Changed

valid

Differences

result.total

  • Changed/version

    − 1

    + 2

  • Added/settings/language

    + "en"

  • Added/users/0

    + {"id":3,"name":"Grace","email":"grace@example.com"}

  • Changed/users/1/email

    − "ada@example.com"

    + "ada@example.org"

  • Removed/users/1

    − {"id":2,"name":"Linus","email":"linus@example.com"}

  • Type changed/limitstring → number

    − "100"

    + 100

Compare JSON by meaning, not by text

This JSON diff tool compares two JSON documents as data. Objects are matched key by key whatever order the keys are in, formatting and indentation are ignored, and every difference is listed with its exact path, what kind of change it is and the old and new values. Arrays of records can be matched by an id field so that a re-sorted list or a row inserted at the top does not show up as everything changed. Export the result as an RFC 6902 JSON Patch or a plain-text report. Both documents stay in your browser; nothing is uploaded.

How to compare two JSON files

  1. Paste the original JSON on the left and the new JSON on the right, or drop a .json file onto each side.
  2. Fix any parse error shown above a pane; it gives the line and column.
  3. Read the list of changes, each with its JSON Pointer path such as /users/2/email, or switch to the tree view to browse them in context.
  4. Turn on Match array items by key and enter the field that identifies a record, usually id.
  5. Filter by added, removed, changed or type changed, then copy the JSON Patch or download a text report.

Why a text diff is the wrong tool for JSON

Two JSON documents can be identical as data and completely different as text. One API returns keys in a different order, one file is minified and the other pretty-printed, one writes 1.0 where the other writes 1. A line-based diff checker flags all of that. A structural diff parses both sides first and compares the values, so only real changes are reported: a key that was added or removed, a value that changed, or a value whose type changed, such as the string "42" becoming the number 42.

Numbers are compared by value with full precision, so 1.50 equals 1.5 while two 20-digit IDs that differ in the last digit are still reported as different, which a comparison through JavaScript numbers would miss.

Added
The key or array item exists only in the new document.
Removed
The key or array item exists only in the original document.
Changed
Same place, same type, different value.
Type changed
The value became a different JSON type, for example an object became an array or a number became a string.

Comparing arrays: by position or by key

By default array items are compared position by position: item 0 with item 0, item 1 with item 1. That is right for lists where order matters, such as coordinates or steps. For lists of records it is not: insert one user at the top and every user after it appears changed.

With Match array items by key, items are paired by an identifying field instead, id by default. Each record is compared with the record that has the same id wherever it sits, so the result says one user was added and one email changed. Matching is used only when every item on both sides is an object with a unique string or number in that field; otherwise the array is compared by position.

The tree view shows both documents merged into one outline. Branches that contain changes open automatically and unchanged ones stay folded, with additions in green, removals in red and changed values shown as old → new. Turn off Only changes to see the unchanged keys around them for context.

Paths, JSON Pointer and JSON Patch

Each change is located with a JSON Pointer (RFC 6901): a slash-separated path from the root such as /orders/0/total, where array items are numbered from zero and the characters ~ and / in a key are written ~0 and ~1. An empty path means the whole document.

The export is a JSON Patch (RFC 6902): a list of add, remove and replace operations that turns the left document into the right one when applied in order. Libraries such as fast-json-patch, jsonpatch for Python and Kubernetes' patch support apply it directly. Array removals are written from the highest index down so that each operation's index is still correct when it runs.

To tidy either document first, format it with the JSON formatter; to convert the result to YAML or CSV, use the data converter.

Najczęstsze pytania

How do I compare two JSON files?
Paste or drop the original JSON on the left and the new JSON on the right. Every difference is listed with its path, the kind of change and the old and new values.
Does the order of keys matter when comparing JSON?
No. Objects are compared key by key, so the same keys in a different order are equal. Whitespace and indentation are ignored too.
How can I compare JSON arrays when the order changed?
Turn on Match array items by key and enter the field that identifies each item, such as id. Items are then paired by that value instead of by position.
What is a JSON Patch?
A JSON Patch, defined in RFC 6902, is a JSON array of operations such as add, remove and replace, each with a path. Applying it to the original document produces the new one.
What does type changed mean?
The value at that path became a different JSON type, for example a number became a string or an object became an array. It usually points to a bug in whatever produced the data.
Can I compare large JSON files?
Yes. Files of several megabytes compare in well under a second on a typical computer, because the parsing and comparison run locally in your browser.
Is my JSON uploaded?
No. Both documents are parsed and compared in your browser and never sent anywhere, so it is safe to compare API responses containing personal data or secrets.