json_decode
Decodes a JSON string.
json_decode Function synopsis
json_decode(
string $json,
?bool $associative = null,
int $depth = 512,
int $flags = 0
): mixed
Parameters
$json
Typestring
The $json string being decoded.
$associative
OptionalType?boolDefault valuenull
When true, JSON objects will be returned as
associative arrays; when false, JSON objects will be returned as objects.
When null, JSON objects will be returned as associative arrays or
objects depending on whether JSON_OBJECT_AS_ARRAY
is set in the $flags.
$depth
OptionalTypeintDefault value512
Maximum nesting depth of the structure being decoded.
The value must be greater than 0,
and less than or equal to 2147483647.
$flags
OptionalTypeintDefault value0
Bitmask of
JSON_BIGINT_AS_STRING,
JSON_INVALID_UTF8_IGNORE,
JSON_INVALID_UTF8_SUBSTITUTE,
JSON_OBJECT_AS_ARRAY,
JSON_THROW_ON_ERROR.
The behaviour of these constants is described on the
JSON constants page.
$flags accepts one or a bitmask of the following constant values:
Return value
Typemixed
Returns the value encoded in $json as an appropriate
PHP type. Unquoted values true, false
and null are returned as true,
false and null respectively. null is returned if the
$json cannot be decoded or if the encoded data is
deeper than the nesting limit.
Changes to the json_decode Function
PHP 8.6
PHP 8.0
- Return type added:
mixed - Parameter type added for parameter #1 (
$json):string - Parameter name of parameter #2 changed:
$assocto$associative - Parameter type added for parameter #2 (
$associative):?bool - Parameter default value added for position #2 (
$associative):null - Parameter type added for parameter #3 (
$depth):int - Parameter default value added for position #3 (
$depth):512 - Parameter name of parameter #4 changed:
$optionsto$flags - Parameter type added for parameter #4 (
$flags):int - Parameter default value added for position #4 (
$flags):0
json_decode(
- $json,
+ string $json,
- $assoc,
+ ?bool $associative = null,
- $depth,
+ int $depth = 512,
- $options
+ int $flags = 0
- )
+ ): mixed PHP 5.4
- Optional parameter added - #4:
$options
json_decode(
$json,
$assoc,
- $depth
+ $depth,
+ $options
) json_decode Function Availability
json_decode Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |