Compare Two JSON Files Online: Find Structural Differences
Comparing two JSON files means finding which keys were added, removed, or changed — at every nesting level. A naive text diff misses differences caused by key reordering or formatting. A structural JSON diff sees through those and shows only real semantic changes.
Paste both JSON files into Jsonic's JSON Diff tool for an instant structural comparison with inline highlights.
Compare JSON nowString diff vs structural diff
A standard text diff tool compares files line by line. Two JSON objects that are semantically identical but formatted differently will show dozens of false differences.
// File A
{"name":"Alice","role":"admin"}
// File B — same data, different formatting
{
"role": "admin",
"name": "Alice"
}
// Text diff: reports every line as changed
// Structural diff: no differences foundA structural diff parses both files first, then compares the parsed values. Key order and whitespace do not affect the result.
What a JSON diff shows
A structural JSON comparison identifies three types of change:
- Added — a key exists in the second file but not the first
- Removed — a key exists in the first file but not the second
- Changed — a key exists in both files but the value differs
// Before
{
"name": "Alice",
"role": "viewer",
"email": "alice@example.com"
}
// After
{
"name": "Alice",
"role": "admin",
"team": "engineering"
}
// Diff result:
// role: "viewer" → "admin" (changed)
// email removed (removed)
// team: "engineering" (added)Nested object comparison
A good JSON diff recurses into nested objects and reports the exact changed path, not just the top-level key.
// Before
{
"user": {
"name": "Alice",
"address": { "city": "London" }
}
}
// After
{
"user": {
"name": "Alice",
"address": { "city": "Berlin" }
}
}
// Diff: user.address.city "London" → "Berlin"Array comparison
Arrays are compared by position. An item added at the beginning shifts every subsequent item and will appear as a change on every index. For order-independent array comparison (treating arrays as sets), you need a more specialized tool or a pre-sort step.
// Before
{"tags": ["api", "json"]}
// After — item inserted at index 0
{"tags": ["rest", "api", "json"]}
// Position-based diff:
// [0]: "api" → "rest"
// [1]: "json" → "api"
// [2]: added "json"Common use cases for JSON comparison
- API versioning — verify a response schema change between v1 and v2
- Config management — see what changed between two environment configs
- Debugging — compare a correct payload with a broken one to isolate the issue
- Data migration — confirm a transformed record matches the expected output
- Code review — review fixture or snapshot changes without noise from reformatting
Comparing JSON files in JavaScript
For programmatic comparison, parse both files and use a deep-equality check or a diff library.
import { diff } from 'json-diff-kit'
const before = JSON.parse(fs.readFileSync('before.json', 'utf8'))
const after = JSON.parse(fs.readFileSync('after.json', 'utf8'))
const result = diff(before, after)
console.log(result)For a step-by-step walkthrough of the diff algorithm and viewer output, see the JSON Diff tutorial.
Compare JSON files in your browser
Paste both payloads into Jsonic's JSON Diff. It performs a structural comparison with inline colour highlighting, line numbers, and collapsed unchanged sections.
Open JSON Diff