PHP sandbox
PHP json_decode() Online
Decode JSON the way PHP does: arrays or stdClass objects, big integers, depth limits and json_last_error_msg(). Runs on real PHP 8.2 on our server when you press Run.
About json_decode()
json_decode() parses a JSON string into PHP values. With $associative = true objects become associative arrays; with false (the default) they become stdClass objects.
On invalid JSON it returns null without a warning, so the sandbox also shows json_last_error_msg(). Add JSON_THROW_ON_ERROR to get a JsonException instead.
Integers too large for 64 bits become floats unless you pass JSON_BIGINT_AS_STRING. The input is used byte for byte: no trimming and no BOM stripping.
Worked example
$json = '{"a":1,"b":[1,2.5,{"c":null}]}';
$data = json_decode($json, true);
echo $data['b'][1]; // 2.5try {
json_decode("{'a':1}", true, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $e) {
echo $e->getMessage(); // Syntax error
}Frequently asked questions
Why does json_decode() return null?
Either the JSON is literally null or decoding failed. Check json_last_error_msg(): common causes are single quotes, trailing commas, comments and invalid UTF-8.
How do I keep large integers exact?
Pass JSON_BIGINT_AS_STRING as a flag; numbers beyond PHP_INT_MAX then come back as strings.
What does the depth argument do?
It is the maximum nesting depth. Deeper input fails with "Maximum stack depth exceeded". A depth of 0 or less throws a ValueError.
Is my input sent to a server?
Yes. These pages run real PHP 8.2 on the w3docs server, so the text you enter is sent there to run, in a sandbox with no network access. Do not paste passwords, keys or personal data.
How much input can I send?
Up to 6,000 bytes across all text fields, which is about 6,000 characters of plain text (accented letters and emoji take 2 to 4 bytes). Larger input is refused before anything is sent.