Online JSON Diff Tool: Compare and Analyze JSON Data Differences
What Is JSON Diff
JSON Diff compares two JSON data structures and identifies differences. It detects additions, deletions, and modifications between two JSON objects. Drop two payloads into our JSON Diff tool to highlight the changes side by side.
Comparison Example
Original JSON:
{
"name": "Alice",
"age": 28,
"hobbies": ["reading", "gaming"]
}
Modified JSON:
{
"name": "Alice",
"age": 29,
"hobbies": ["reading", "coding"],
"email": "alice@example.com"
}
Diff Result:
{
"age": { "old": 28, "new": 29 },
"hobbies[1]": { "old": "gaming", "new": "coding" },
"email": { "added": "alice@example.com" }
}
Why You Need JSON Diff
- API response validation: Compare API returns with expected values
- Config change detection: Compare configuration file modifications
- Data migration verification: Confirm data migration correctness
- Code review: Compare JSON output between two versions
- Automated testing: Assert data changes in tests
- Version control: Track JSON data change history
Diff Result Types
| Change Type | Description | Marker |
|-------------|-------------|--------|
| Added | Key doesn't exist in original | + or added |
| Deleted | Key exists in original but not modified | - or deleted |
| Changed | Key exists but values differ | ~ or changed |
| Unchanged | Key and value are the same | No marker |
How to Use an Online Tool
Using ToolVault's JSON Diff Tool:
- Enter original JSON on the left
- Enter modified JSON on the right
- The tool auto-compares and highlights differences
- Shows specific additions, deletions, and changes
- Copy Diff results supported
JSON Diff in Code
JavaScript
// Deep compare two objects
function deepDiff(oldObj, newObj, path = '') {
const diffs = {};
const allKeys = new Set([...Object.keys(oldObj), ...Object.keys(newObj)]);
for (const key of allKeys) {
const currentPath = path ? `${path}.${key}` : key;
if (!(key in oldObj)) {
diffs[currentPath] = { type: 'added', value: newObj[key] };
} else if (!(key in newObj)) {
diffs[currentPath] = { type: 'deleted', value: oldObj[key] };
} else if (typeof oldObj[key] === 'object' && typeof newObj[key] === 'object') {
Object.assign(diffs, deepDiff(oldObj[key], newObj[key], currentPath));
} else if (oldObj[key] !== newObj[key]) {
diffs[currentPath] = { type: 'changed', old: oldObj[key], new: newObj[key] };
}
}
return diffs;
}
Python
def deep_diff(old, new, path=''):
diffs = {}
all_keys = set(list(old.keys()) + list(new.keys()))
for key in all_keys:
current_path = f"{path}.{key}" if path else key
if key not in old:
diffs[current_path] = {'type': 'added', 'value': new[key]}
elif key not in new:
diffs[current_path] = {'type': 'deleted', 'value': old[key]}
elif isinstance(old[key], dict) and isinstance(new[key], dict):
diffs.update(deep_diff(old[key], new[key], current_path))
elif old[key] != new[key]:
diffs[current_path] = {'type': 'changed', 'old': old[key], 'new': new[key]}
return diffs
FAQ
Can JSON Diff Handle Large Files?
Depends on implementation. Simple in-memory comparison may be slow for large files (>10MB). Use streaming Diff algorithms or specialized libraries (deep-diff, jsondiffpatch).
Can Diff Results Be Merged?
Some tools support "merge" functionality, applying Diff results to the original JSON. This requires the Diff to contain complete change info (old and new values).
How to Handle Array Order Changes?
Array Diff has two strategies: position-based comparison (simple but may be inaccurate) and content-based comparison (smarter but more complex). Choose based on your use case.
This article is brought to you by ToolVault. More developer tools at the homepage.
Related Tools
Related Articles
HTML Table to JSON: How to Preserve Rows, Columns and Structure
Converting an HTML table from a web page to JSON — how to keep headers, handle merged cells and nested structure? Step-by-step with our HTML table to JSON tool.
Excel to JSON: Dates Become Numbers / Chinese Garbled — Fix
When converting Excel to JSON, dates turn into numbers like 44927, Chinese is garbled, empty cells vanish? Explains Excel serial dates and encoding pitfalls, with our Excel to JSON tool.
The Complete Guide to Table Format Conversion: Excel, CSV, JSON, Markdown, and HTML
A full walkthrough of converting between Excel, CSV, JSON, Markdown, and HTML tables: format characteristics, conversion paths, hands-on workflows, and common pitfalls — 12 free online converters in one place.