How do I parse JSON string in PHP?

PHP has two built-in functions json_encode() and json_decode() to encode PHP objects into JSON string and decode JSON strings into PHP objects. To parse a JSON string, you can use the json_decode() function. This function recursively converts the passed JSON string into the corresponding PHP objects. You can control the parsing flow by passing a set of bitmasks to the JSON decoder function. If the JSON cannot be parsed, or the nested JSON data has a depth greater than the recursion limit, it returns NULL. The PHP JSON parser only works with UTF-8 encoded strings. In this PHP JSON Parse example, we use the json_decode() function to decode JSON strings into PHP objects. Click Execute to run the PHP Parse JSON Example online and see the result.
Loading...