JSON Diff Tool
Compare JSON objects and visualize differences with detailed analysis. Our JSON diff tool helps you identify changes between two JSON structures, making it perfect for API testing, configuration management, and debugging.
Key Features:
- • Deep comparison of nested objects and arrays
- • Visual highlighting of additions, deletions, and modifications
- • Path tracking to identify exact location of changes
- • Side-by-side comparison view
- • Export diff results
Comparison Tools
Original JSON
The first JSON object to compare
Modified JSON
The second JSON object to compare
Differences Found
🔍 How It Works
📊 Legend
Try These Examples
Click any example to load it, then hit Compare to see differences
User Profile Update
A user changed their email, city, added skills and phone
API Version Change
Compare API v1 vs v2 response — fields renamed and added
Config Change
Database config updated — new pool settings, debug toggled
📚 Complete Guide to Comparing JSON
What is JSON Diffing?
JSON diffing is the process of comparing two JSON documents to find every difference between them — added fields, removed fields, and changed values. Unlike plain text diff tools (which compare line by line), a JSON diff tool understands the structure of JSON. It knows that {"a":1,"b":2} and {"b":2,"a":1} are semantically identical even though the text is different. This structural awareness makes JSON diff tools far more useful than generic text comparisons for working with data.
Our diff tool performs a deep recursive comparison: it walks through every level of nesting in both documents and reports the exact path where each difference occurs. All processing happens in your browser — your data is never sent to a server.
Understanding the Three Change Types
Added Properties (➕)
A property exists in the modified JSON but not in the original. This typically means a new field was introduced — for example, an API adding a new phone field to a user object, or a config file gaining a new feature flag.
// Original
{"name": "Alice", "email": "alice@example.com"}
// Modified — "phone" was added
{"name": "Alice", "email": "alice@example.com", "phone": "+1-555-0123"}
// Diff result: ADDED at path "phone" → "+1-555-0123"Removed Properties (➖)
A property exists in the original JSON but not in the modified version. This means a field was deleted or deprecated — for example, removing a legacy fax field or dropping a feature that is no longer supported.
// Original
{"name": "Alice", "fax": "555-0199", "email": "alice@example.com"}
// Modified — "fax" was removed
{"name": "Alice", "email": "alice@example.com"}
// Diff result: REMOVED at path "fax" → "555-0199"Modified Values (🔄)
The same key exists in both documents, but its value changed. This is the most common change type — an updated email address, a bumped version number, a changed configuration value.
// Original
{"name": "Alice", "age": 30, "city": "New York"}
// Modified — "age" and "city" changed
{"name": "Alice", "age": 31, "city": "San Francisco"}
// Diff results:
// MODIFIED at path "age" → 30 changed to 31
// MODIFIED at path "city" → "New York" changed to "San Francisco"Real-World Use Cases for JSON Comparison
API Testing and Contract Verification
When building or consuming APIs, you need to verify that responses match expected structures. Compare a saved "golden" response against the actual response to catch regressions. This is especially important when:
- Upgrading API versions — diff the v1 and v2 responses to document exactly what changed for your consumers.
- Running integration tests — compare actual responses against expected fixtures to catch bugs before deployment.
- Monitoring third-party APIs — detect when an external API changes its response format unexpectedly.
Configuration Management
JSON configuration files (package.json, tsconfig.json, app settings) change frequently. Diffing helps you:
- Review pull requests — understand exactly what changed in a config file without reading the entire document.
- Compare environments — diff your staging config against production to find discrepancies that could cause deployment failures.
- Audit changes — track what settings changed, when, and by whom across deployments.
Data Migration and Synchronization
When moving data between systems (databases, APIs, file formats), diff the source and destination records to verify that nothing was lost or corrupted. This is critical for:
- Database migrations — compare records before and after a schema migration to ensure data integrity.
- ETL pipelines — validate that transformed data matches expectations at each stage.
- Replication verification — confirm that replicated data matches the source system.
Resolving Merge Conflicts in JSON Files
Git merge conflicts in JSON files are notoriously difficult to resolve because JSON has strict syntax — a single misplaced comma breaks the entire file. When you hit a merge conflict:
- Extract the "ours" and "theirs" versions of the JSON into separate files.
- Paste both versions into a diff tool to see exactly what each side changed.
- Decide for each difference which version to keep (or combine both changes).
- Validate the merged result to ensure it is still valid JSON.
How to Diff JSON Programmatically
JavaScript / Node.js
// Simple deep comparison
function jsonDiff(obj1, obj2, path = '') {
const diffs = [];
const allKeys = new Set([
...Object.keys(obj1 || {}),
...Object.keys(obj2 || {})
]);
for (const key of allKeys) {
const fullPath = path ? `${path}.${key}` : key;
if (!(key in (obj1 || {}))) {
diffs.push({ type: 'added', path: fullPath, value: obj2[key] });
} else if (!(key in (obj2 || {}))) {
diffs.push({ type: 'removed', path: fullPath, value: obj1[key] });
} else if (typeof obj1[key] === 'object' && typeof obj2[key] === 'object') {
diffs.push(...jsonDiff(obj1[key], obj2[key], fullPath));
} else if (obj1[key] !== obj2[key]) {
diffs.push({ type: 'modified', path: fullPath,
oldValue: obj1[key], newValue: obj2[key] });
}
}
return diffs;
}Python
import json
from deepdiff import DeepDiff # pip install deepdiff
with open('original.json') as f:
original = json.load(f)
with open('modified.json') as f:
modified = json.load(f)
diff = DeepDiff(original, modified, ignore_order=True)
print(json.dumps(diff, indent=2, default=str))Command Line (jq + diff)
# Sort keys and format both files, then diff diff <(jq -S '.' original.json) <(jq -S '.' modified.json) # Using jd (JSON diff tool) jd original.json modified.json
JSON Diff vs. Text Diff: Why It Matters
A standard text diff (like diff or Git's built-in diff) compares files line by line. This causes problems with JSON because:
- Key reordering creates false positives — if you sort the keys in a JSON file, a text diff shows every line as changed even though the data is identical. A JSON-aware diff ignores key order.
- Formatting changes mask real changes — if someone reformats JSON from 2 spaces to 4 spaces, a text diff shows every line as changed. A JSON diff ignores whitespace.
- Context is lost — a text diff shows
"age": 30changed to"age": 31but does not tell you that this is at pathuser.profile.age. A JSON diff provides the full path. - Array handling is naive — text diffs treat arrays as lines of text. JSON diffs can compare arrays element by element, detecting insertions, deletions, and moves.
Handling Tricky Comparison Scenarios
Null vs. Missing vs. Undefined
In JSON, there is a meaningful difference between a key with a null value and a key that does not exist at all. {"name": null} means "name is explicitly empty," while {} means "name was not provided." A good diff tool distinguishes between these — our tool reports a missing key as "removed" and a null value change as "modified."
Array Order Sensitivity
JSON object key order is not significant (per the spec), but array element order is. [1, 2, 3] and [3, 2, 1] are different arrays. Be aware of this when comparing API responses — if the server does not guarantee array order, you may see false differences. Sort arrays before comparing if order does not matter to your use case.
Type Changes
Watch for values that change type between documents. A common example: an API returns "id": 123 (number) in one version and "id": "123" (string) in another. The values look similar but are semantically different and will break code that expects a specific type.
Best Practices for Comparing JSON
- Normalize before comparing — sort keys, consistent formatting, and consistent null handling reduce noise in your diffs.
- Validate both inputs first — comparing invalid JSON produces meaningless results. Use our validator first.
- Ignore expected differences — timestamps, auto-generated IDs, and random tokens will always differ. Filter these out when comparing.
- Use path notation — when reporting diffs, include the full JSON path so others can locate the change in the document quickly.
- Version your baseline — keep a "golden" copy of expected JSON responses in version control for regression testing.
- Watch for type coercion —
0vsfalse,""vsnull, and1vs"1"are all different in JSON even though some languages treat them as equivalent. - Document breaking changes — when comparing API versions, flag changes that remove fields or change types as breaking changes that need migration plans.
🔗 Related Tools & Resources
Explore these related JSON tools and guides