PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular

json_decode

Tags: PHP 5.x PHP 7.x PHP 8.x

json_decode — Decodes a JSON string.

Description

json_decode(
    string $json,
?bool $associative = null,
int $depth = 512,
int $flags = 0
): mixed
Takes a JSON encoded string and converts it into a PHP variable.

Parameters

json
The json string being decoded.
associative
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
Maximum nesting depth of the structure being decoded.
flags
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.

Return Values

Returns the value encoded in json in appropriate PHP type. 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.