Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Aaron Agostini6,285 Points
Simon Klit1,686 Points
What exactly do you need to know?
json_encode is a native PHP function that was added in 5.2.0. It accepts any type of UTF-8 encoded input except for resources (http://php.net/manual/en/language.types.resource.php), and encodes it to JSON.
It has a very simple syntax. Here is an example using an array:
<?php $arr = array("foo" => "bar", "hello" => "world"); echo json_encode($arr); ?>
Likewise, you can use json_decode to convert some JSON to a PHP variable.
More information regarding the "options" and "depth" arguments that the function also accepts, can be found here: http://php.net/manual/en/function.json-encode.php