json_decode
Decodes a JSON string
&reftitle.description;
mixedjson_decode
stringjson
boolassocfalse
intdepth512
Takes a JSON encoded string and converts it into a PHP variable.
&reftitle.parameters;
json
The json string being decoded.
assoc
When &true;, returned objects will be converted into
associative arrays.
depth
User specified recursion depth.
&reftitle.returnvalues;
Returns an object or if the optional
assoc parameter is &true;, an associative
array is instead returned.
&reftitle.examples;
json_decode examples
]]>
&example.outputs;
int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
array(5) {
["a"] => int(1)
["b"] => int(2)
["c"] => int(3)
["d"] => int(4)
["e"] => int(5)
}
]]>
Another example
{'foo-bar'}; // 12345
?>
]]>
common mistakes using json_decode
]]>
&reftitle.notes;
The JSON spec is not JavaScript, but a subset of JavaScript.
This function will return &false; if the JSON encoded data is deeper than
the recursion depth.
&reftitle.changelog;
&Version;
&Description;
5.3.0
Added the optional depth. The default recursion depth was increased from 128 to 512
5.2.3
The nesting limit was increased from 20 to 128
&reftitle.seealso;
json_encode