JSON Diff
Compare two JSON payloads and see added, removed or changed fields for debugging, reviews and API checks.
Back to all tools on ToolForge
JSON A
JSON B
Differences
About JSON Diff
The JSON Diff tool lets you compare two JSON payloads and see added, removed or changed fields for debugging and reviews.
JSON Diff Comparison Algorithm
// Recursive JSON diff function
function diff(objA, objB, path = '') {
const differences = [];
// Check for removed and changed keys
for (const key in objA) {
const currentPath = path ? `${path}.${key}` : key;
if (!(key in objB)) {
differences.push(`Removed: ${currentPath}`);
} else if (typeof objA[key] === 'object' && typeof objB[key] === 'object') {
differences.push(...diff(objA[key], objB[key], currentPath));
} else if (objA[key] !== objB[key]) {
differences.push(`Changed: ${currentPath} = ${objA[key]} → ${objB[key]}`);
}
}
// Check for added keys
for (const key in objB) {
const currentPath = path ? `${path}.${key}` : key;
if (!(key in objA)) {
differences.push(`Added: ${currentPath} = ${objB[key]}`);
}
}
return differences;
}
Common Use Cases for JSON Diff
- API Development: Compare request/response payloads between API versions
- Configuration Management: Review changes in config files between deployments
- Debugging: Identify why two JSON responses differ in production vs staging
- Data Migration: Verify data transformations preserve expected fields
- Code Review: Show exactly what changed in JSON fixtures or test data
- Webhook Testing: Compare webhook payloads across different event triggers
Example JSON Diff
JSON A (original):
{
"name": "John",
"age": 30,
"city": "New York"
}
JSON B (modified):
{
"name": "John",
"age": 31,
"email": "[email protected]"
}
Differences:
Changed: age = 30 → 31 Removed: city Added: email = [email protected]
Frequently Asked Questions
- How does JSON diff work?
- JSON diff compares two JSON objects by recursively walking through all keys and values. It identifies three types of differences: added keys (present in B but not A), removed keys (present in A but not B), and changed values (same key but different value). The comparison is type-aware and handles nested objects and arrays.
- What types of JSON differences can this tool detect?
- This tool detects: added fields (new keys in the second JSON), removed fields (missing keys from the first JSON), changed values (same key but different value), and nested differences (changes deep within object hierarchies). Array comparisons check for value differences at each index.
- When should I use JSON diff?
- JSON diff is useful for: comparing API request/response payloads before and after changes, reviewing configuration file modifications, debugging webhook data changes, validating data transformations, code review for JSON files, and identifying what changed between two versions of structured data.
- Does this tool modify my JSON data?
- No. This tool only reads and compares your JSON data without modifying it. All processing happens in your browser using JavaScript's JSON.parse() method. Your data is never sent to any server or stored persistently.