This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
JSON is a very common format for sharing data on the web and many APIs respond with JSON. It's also a common format for configuration files. PHP has a handy function for turning JSON object into PHP objects and arrays.
Additional Parameters for json_decode
assoc – When TRUE, returned objects will be converted into associative arrays.
depth – User specified recursion depth.
options – Bitmask of JSON decode options. Currently there are two supported options. The first is JSON_BIGINT_AS_STRING that allows casting big integers to string instead of floats which is the default. The second option is JSON_OBJECT_AS_ARRAY that has the same effect as setting assoc to TRUE.
NOTE ON RETURN VALUES: Returns the value as the appropriate PHP type (object or array). 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 recursion limit.
Validating & Formatting JSON
The JSON Formatter was created to help with debugging JSON. As JSON data is often output without line breaks to save space, it is extremely difficult to actually read and make sense of it. This little tool attemps to solve the problem by formatting the JSON data so that it is easy to read and debug by human beings.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up