I\'m building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode
json_encode
Simple way for php>5.4: like in Facebook graph
$Data = array('a' => 'apple', 'b' => 'banana', 'c' => 'catnip'); $json= json_encode($Data, JSON_PRETTY_PRINT); header('Content-Type: application/json'); print_r($json);
Result in browser
{ "a": "apple", "b": "banana", "c": "catnip" }