A PHP library providing pretty printing JSON strings for PHP < 5.4 based upon this StackOverflow answer by Kendall Hopkins.
{
"require": {
"markenwerk/json-pretty-printer": "~1.0"
}
}
require_once('path/to/vendor/autoload.php');
Default indentation is one tab.
use Markenwerk\JsonPrettyPrinter;
$jsonString = json_encode($myObject);
$prettyPrinter = new JsonPrettyPrinter\JsonPrettyPrinter();
$prettyPrinted = $prettyPrinter
->setIndentationString(' ')
->prettyPrint($jsonString);
Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.
PHP JSON Pretty Printer is under the MIT license.