Skip to content

How to compare two JSON files and see what changed

Why a text diff misleads, what a JSON comparison reports, and a worked example with a before and after file.

By OpenAnyDoc ·

The short answer

Compare the data, not the text: a JSON-aware comparison matches objects key by key and lists position by position, so new indentation or a different key order does not count as a change. OpenAnyDoc's Compare JSON does this in your browser without uploading either file, and lists every added, removed and changed value with its path, such as $.settings.language.

Why a line-by-line diff misleads

A text diff compares lines. If one file was saved on a single line and the other was formatted with 2 spaces, every line differs. If a program wrote the same keys in another order, the diff shows lines removed in one place and added in another, although the data is the same.

A JSON comparison reads both files first and compares what they hold. Whitespace never counts, and key order counts only if you ask for it.

A worked example

Two versions of a synthetic account record. In the second, the plan was upgraded, a feature was added, the language changed, a coupon was used up, a trial date appeared, and the keys came out in another order:

  • Before: {"id":"A-1042","plan":"basic","seats":5,"features":["export","search"],"settings":{"theme":"light","language":"en"},"coupon":"WELCOME"}
  • After: {"plan":"pro","id":"A-1042","seats":5,"features":["export","search","share"],"settings":{"language":"ar","theme":"light"},"trialEnds":"2026-12-31"}

What the comparison shows

With Ignore key order on, as it is by default, the summary reads "2 added, 1 removed, 2 changed." and the list underneath names each difference:

  • Changed: $.plan ("basic" became "pro").
  • Added: $.features[2] ("share").
  • Changed: $.settings.language ("en" became "ar").
  • Removed: $.coupon.
  • Added: $.trialEnds.
  • Turn Ignore key order off and the same five stay, followed by "2 objects have their keys in another order.": the whole record ($) and $.settings, each listed as Key order.
  • id, seats and settings.theme are not listed, because they did not change.

How to compare two JSON files, step by step

Both files are read on your device:

  • Open Compare JSON and choose the first file, drop it on the page or paste the text. It opens on the Compare tab.
  • Paste the second document into the box, drop its file on the box, or press Choose a file.
  • Read the summary line, then the list of differences. Click one and both sides scroll to it.
  • The open document is on the left and the second document on the right, both indented with 2 spaces. With Ignore key order on, keys are shown in alphabetical order on both sides, so equal objects line up.
  • The changed lines are marked on each side, so you can read the values around a change.

Lists, limits and invalid files

Objects are matched by key, but lists are matched by position: item 0 with item 0, item 1 with item 1. If "share" is put at the start of ["export","search"], the result is not one insertion but three lines: $.features[0] changed, $.features[1] changed and $.features[2] added, because every item moved one place.

When you see a run of changes at the end of a list, check whether one item was inserted or deleted near its start. The list shows the first 300 differences, and each side shows up to 20,000 lines. The first file can be up to 10 MB.

The second document is checked as you paste it: if it is not valid JSON, the parser's message appears under the box instead of a comparison. Fix it in the JSON validator, which shows the line and column and repairs common mistakes such as trailing commas. The guide to unexpected token errors explains each message.

Does key order matter when comparing JSON?

Usually not: in JSON, {"a":1,"b":2} and {"b":2,"a":1} hold the same data, so Compare JSON treats them as equal by default. Order can matter when a person reads the file, or when a test compares raw text. Turn Ignore key order off and every object whose keys moved is reported as Key order.

How do I compare an API response with a saved copy?

Open the saved .json file in Compare JSON first, so it sits on the left. Then copy the new response from your API client or the browser's network panel and paste it into the box on the Compare tab. Every field that was added, removed or changed since the saved copy is listed with its path.

Can I compare two JSON Lines files?

Yes, with one extra step, because the box reads one JSON document. Open the first .jsonl file in the JSON viewer, which reads each line as an item of a list, then switch to Compare. Open the second file in another tab, choose Copy formatted from the Copy menu and paste it. JSON vs JSON Lines explains the format.

Are my files uploaded when I compare them?

No. Both documents are read and compared by your own browser, and nothing is saved or shared, so there is no link to send either. That matters when the files hold API keys or customer records. Our comparison of jsonformatter.org and Code Beautify shows how other JSON sites describe what they send to their servers.

Questions?

Write to support@openanydoc.com and describe the two files and the difference you expected to see (no personal data).