For those who work often with JSON in PHP, PHP 5.4 came out with some nice new options for the json_encode function. In particularĀ JSON_PRETTY_PRINTĀ which outputs JSON in a more human readable format.

Unfortunately for those of us stuck with PHP 5.3 for whatever reason, we don’t have this option available.

In comes this simple JSON Pretty service to the rescue:

$jsonPretty = new Camspiers\JsonPretty\JsonPretty;

echo $jsonPretty->prettify(array(‘test’ => ‘test’));

JSON pretty can have an array as input or a JSON string, and the result with be pretty human readable JSON.

You can find the source and installation instructions on github.