← All built-ins / json_decode()
json_decode()
json_decode(string $s): mixed
Parameters
| Name | Type | Description |
|---|---|---|
| $s | string | JSON text |
| $assoc | bool | accepted for PHP compatibility; maps come as maps either wayoptional |
Return value
The decoded value (maps as maps, scalars as scalars); null on invalid JSON.
Example
$d = json_decode('{"n": 42, "tags": ["a", "b"]}');
echo $d["n"], " ", count($d["tags"]), " ", $d["tags"][0];42 2 a