Compare PHP JSON Online

Paste two PHP JSON objects or arrays. See what was added, removed, or changed — key by key.

🔒 100% private — runs entirely in your browser

or try sample data

What is PHP JSON Diff?

PHP JSON Diff compares two JSON objects — typically the output of json_encode() from PHP arrays or objects — and shows you exactly which keys were added, removed, or modified. PHP's json_decode() and json_encode() handle serialization, but PHP has no built-in function to diff two JSON structures.

PHP developers often work with JSON for API responses, Laravel/Symfony configs, and database records. While array_diff_assoc() handles flat arrays, it doesn't recurse into nested structures. This tool gives you a full recursive diff with color-coded highlighting — no Composer packages needed.

Paste your JSON (e.g., Laravel config arrays, API payloads, or JSON_PRETTY_PRINT output). The tool handles nested objects, arrays, nulls, and mixed types. Everything runs client-side — your data never leaves your machine.

PHP JSON Comparison — Code Examples

json_decode() with array_diff_assoc()

$json1 = '{"name": "Alice", "role": "admin", "active": true}';
$json2 = '{"name": "Alice", "role": "editor", "active": true}'; $arr1 = json_decode($json1, true);
$arr2 = json_decode($json2, true); $diff = array_diff_assoc($arr1, $arr2);
print_r($diff);
// Array ( [role] => admin ) $added = array_diff_key($arr2, $arr1);
$removed = array_diff_key($arr1, $arr2);

array_diff_assoc() only compares top-level keys. It doesn't recurse into nested arrays or objects.

Recursive array diff function

function array_diff_recursive($arr1, $arr2) { $diff = []; foreach ($arr1 as $key => $val) { if (!array_key_exists($key, $arr2)) { $diff[$key] = ['removed' => $val]; } elseif (is_array($val) && is_array($arr2[$key])) { $nested = array_diff_recursive($val, $arr2[$key]); if (!empty($nested)) $diff[$key] = $nested; } elseif ($val !== $arr2[$key]) { $diff[$key] = ['old' => $val, 'new' => $arr2[$key]]; } } foreach (array_diff_key($arr2, $arr1) as $key => $val) { $diff[$key] = ['added' => $val]; } return $diff;
} $diff = array_diff_recursive( ['db' => ['host' => 'localhost', 'port' => 3306]], ['db' => ['host' => 'prod.db', 'port' => 5432], 'cache' => 'redis']
);

A recursive approach that handles nested arrays. For quick visual comparison, use this online tool instead.

String comparison via json_encode()

$config1 = ['features' => ['auth', 'logging'], 'debug' => true];
$config2 = ['features' => ['auth', 'logging', 'caching'], 'debug' => false]; $json1 = json_encode($config1, JSON_PRETTY_PRINT);
$json2 = json_encode($config2, JSON_PRETTY_PRINT); if ($json1 !== $json2) { echo "Configs differ!\n"; // But which keys? Use this tool to find out.
}

String comparison tells you if something changed but not what. Use structural comparison for actionable diffs.

PHP JSON Comparison Gotchas

stdClass is the default decode type

json_decode($json) returns stdClass objects by default, not arrays. Use json_decode($json, true) to get associative arrays. Comparing a stdClass to an array will always show differences even if the data is identical.

Integer keys get coerced to strings

JSON object keys are always strings, but PHP array keys can be integers. json_decode('{"0": "a"}', true) produces [0 => "a"] with an integer key. When you json_encode() this back, it becomes ["a"] (a JSON array), not an object. This round-trip changes the structure silently.

Non-UTF8 strings fail silently

json_encode() returns false for strings with invalid UTF-8 bytes, and json_last_error() reports JSON_ERROR_UTF8. Always validate encoding with mb_check_encoding($str, 'UTF-8') before encoding to avoid silent data loss.

Frequently Asked Questions

How do I compare two PHP JSON objects online?

Paste your JSON objects into the two panels and click Compare. The tool highlights added, removed, and modified keys with color-coded diffs.

Can I compare nested PHP arrays as JSON?

Yes. The tool performs deep comparison of nested objects, arrays, and mixed structures at any depth. Nested changes are shown with path-based highlighting.

Should I use stdClass or associative arrays for JSON?

Use json_decode($json, true) for associative arrays — they're easier to work with in PHP. Both serialize to identical JSON output with json_encode().

Is my PHP JSON data safe?

Yes. This tool runs entirely in your browser using client-side JavaScript. Your data is never sent to any server, making it safe for comparing sensitive config data.

Can I compare Laravel config arrays?

Yes. Export your Laravel config to JSON with json_encode(config('app'), JSON_PRETTY_PRINT) and paste the result. The tool compares all nested keys structurally.

Does this handle PHP's JSON_PRETTY_PRINT format?

Yes. Paste JSON in any formatting — minified or pretty-printed with JSON_PRETTY_PRINT. The tool parses the structure, not the whitespace.