CKTIS / PHP
json_decode()
Parse UTF-8 JSON into PHP values.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixedParse UTF-8 JSON into PHP values. By default objects become stdClass; associative true makes them arrays, while a null option follows JSON_OBJECT_AS_ARRAY. Valid JSON null and malformed JSON both produce null under default error handling. Use JSON_THROW_ON_ERROR to distinguish parse failure.
Signature
json_decode(string $json, ?bool $associative = null, int $depth = 512, int $flags = 0): mixed
Example output
["stdClass",2,null,"JsonException"]
Examples
<?php
$object = json_decode("{\"x\":2}"); $map = json_decode("{\"x\":2}",true);
try { json_decode("[",true,512,JSON_THROW_ON_ERROR); } catch (JsonException $e) { $bad = get_class($e); }
echo json_encode([get_class($object),$map["x"],json_decode("null"),$bad]);
Result
["stdClass",2,null,"JsonException"]