How do I decode JSON in PHP?

To decode a JSON file or string in PHP, you can use the json_decode(string, assoc, depth, options) function. The first parameter specifies the string to be decoded. The second parameter is optional and specifies whether the returned object should be converted to an associative array. By default, the json_decode() function recursively decodes JSON with a depth of 512. You can set a different recursion depth in the third parameter. If the JSON cannot be decoded or the nesting depth of the data is greater than the recursion limit, the decode function returns NULL. In this PHP decode JSON example, we use the json_decode() function to convert a JSON string into a PHP variable using default values. Click Execute to run the PHP JSON Decode Example online and see the result.
Loading...