PHP JSON Decode Example

Convert a JSON string to a PHP array or object with json_decode(). Edit the code below and press Run to execute it with real PHP in your browser.

Code Editor
Output
Name: John
Age: 30
City: New York

How this json decode example works

Pass true as the second argument to get an associative array; without it you get an object and use ->. Invalid JSON returns null, so check errors as shown on the json_decode() reference page.