$data = array( 'name' => 'John Doe', 'age' => 30, 'email' => 'johndoe@example.com' ); $json = json_encode($data); echo $json; // Output: {"name":"John Doe","age":30,"email":"johndoe@example.com"}
$json = '{"name":"John Doe","age":30,"email":"johndoe@example.com"}'; $data = json_decode($json); echo $data->name; // Output: John DoeThis example decodes a JSON string into a PHP object using the `json_decode()` function. The object can then be accessed using object notation. These examples use the PHP JSON built-in library.