Skip to the content
GigaJSON
All tools
Format and check
View and query
Convert
JSON to code
Encode and decode
Sample files
Guides Open GigaJSON

Compare two JSON files: values, key order and saved history

· 4 min read · By Amir Badi

You want a JSON diff to answer one question: did the data change? Indentation and shuffled keys shouldn't get in the way of that answer. Open GigaJSON JSON Diff, paste the before and after documents, and leave Ignore key order on so you compare values.

Below are two small config files you can copy, then the point where I'd switch from a one-off comparison to the workspace's saved history. The examples and screenshots use synthetic data.

GigaJSON JSON Diff showing changed retry and timeout settings and an added audit settingGigaJSON JSON Diff showing changed retry and timeout settings and an added audit setting (dark theme)
Compare the before and after configurations locally. Added and removed lines show the values that changed. Screenshots follow the page theme. Click to view full size.

A before-and-after example

Paste this as the first document:

{
  "service": "orders-api",
  "retries": 2,
  "timeoutMs": 3000,
  "features": {
    "email": true,
    "sms": false
  }
}

And this as the second:

{
  "timeoutMs": 5000,
  "service": "orders-api",
  "retries": 3,
  "features": {
    "sms": false,
    "email": true,
    "audit": true
  }
}

You're looking for three changes: retries went from 2 to 3, timeoutMs from 3000 to 5000, and someone added features.audit. service, email and sms moved around in the text, but their values stayed the same.

In the JSON Diff tool:

  1. Paste the first document into Original, or use its Open file button.
  2. Paste the second into Changed, or pick the second file.
  3. Leave Ignore key order checked. The result updates once both inputs parse.
  4. Read the added and removed lines. A replaced value can show as one removed line plus one added line, so the line counts don't equal the number of changed properties.

Both inputs and the comparison stay in your browser. You need no account, and no server processes your documents. The site's separate analytics is in the privacy policy.

Object order and array order are different

An object maps names to values. For most data comparisons you'd treat these two as the same:

{"name": "Ada", "active": true}
{"active": true, "name": "Ada"}

The JSON specification calls objects unordered collections and arrays ordered sequences. That's why the diff tool can ignore key order and still care about array positions. JSON specification, RFC 8259

These two arrays differ:

["queued", "running", "complete"]
["complete", "running", "queued"]

The order might be a timeline, a priority list or a ranking. If a tool sorted every array for you, it would hide real changes like that one.

When an API returns a collection in random order, decide what identifies a record. To compare by id, you have to line the records up by id first; a text diff can't join two tables for you.

Normalize only what you mean to ignore

For a small array of records with unique string IDs, this jq query puts them in a fixed order:

sort_by(.id)

Applied to this input:

[{"id": "b", "total": 20}, {"id": "a", "total": 10}]

it returns:

[{"id": "a", "total": 10}, {"id": "b", "total": 20}]

Run the same query on both inputs before you compare. You can try it in the jq Playground, and the jq manual documents sort_by. Check that the IDs are unique first. With duplicate IDs you can't tell which record matches which, and sorting won't fix that.

Timestamps and request IDs add noise too. If your test should ignore a field that changes on every run, remove it from both working copies, write down that you did, and keep the originals. Don't delete fields just because they make the diff messy.

Use History when you keep editing one document

Two pasted inputs work well for a one-off check. When you edit a payload again and again, use the GigaJSON workspace, which keeps the earlier state attached to the document.

Open the document and go to History. Save a restore point before a significant change, make the edit, then select the saved version. Changes compares it with the current document, and Full JSON shows the saved content. Compare opens the full diff when the two differ.

GigaJSON History comparing an original API configuration with the edited documentGigaJSON History comparing an original API configuration with the edited document (dark theme)
History keeps the selected saved version next to its changes from the current document. Screenshots follow the page theme. Click to view full size.

I do this before a cleanup or a transform, so I can see what it changed before I call the result done. A change that makes JSON valid can still change what it means, so read the values as well as the syntax.

Saved documents and versions live in your browser's local storage. Download a backup of anything important: clearing site data or losing the browser profile deletes that history.

Rounded numbers hide differences

No formatter can bring back a number that something already rounded. A numeric ID such as 12345678901234567890 is past JavaScript's safe integer range. If both documents get converted to ordinary JavaScript numbers first, the displayed values can look equal while their last digits differ.

So take precision warnings seriously when you compare. Store IDs as quoted strings where you can, and read how to preserve large JSON numbers before you decide two large numeric IDs match. GigaJSON's workspace keeps the original source until you accept rounding, but its parsed views and comparisons don't do arbitrary-precision arithmetic.

When to use something else

The browser tool suits meaningful changes in documents of a manageable size. Diffing two huge documents takes more memory and time than opening one, so being able to view a large file doesn't mean you can diff it.

For automated checks, write your rules into a repeatable test: whether key order matters, whether array order matters, which fields you ignore, and how you keep numeric precision. A screenshot of a clean diff helps while you debug, but your test suite should hold the actual rules.

Start with the two-file comparison, and move to the workspace when you want edits, queries and restore points next to the result.

Questions

Can I compare JSON while ignoring key order?

Yes. GigaJSON's JSON Diff tool has Ignore key order switched on by default. It sorts object keys before comparing and leaves arrays in their order.

Are my JSON files uploaded for comparison?

No. Your browser runs the comparison. The website's separate usage analytics is covered in its privacy policy.

Does ignoring key order also ignore array order?

No. Position matters in a JSON array, so moving an element counts as a difference. If records should match by an ID, sort both arrays by that ID before you compare.

More from the blog