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"
}