json pretty printing

PHP 5.4 offers the JSON_PRETTY_PRINT option for use with the json_encode() call.

http://php.net/manual/en/function.json-encode.php

normal json

{"a":"apple","b":"banana","c":"catnip"}

pretty json

{
"a": "apple",
"b": "banana",
"c": "catnip"
}
$json_pretty = print_r(json_encode($data, JSON_PRETTY_PRINT),true);
echo "<pre>";
echo $json_pretty;
echo "</pre>";

Related posts:

This entry was posted in knowledge, php, เกร็ดความรู้. Bookmark the permalink.