Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

A PHP library providing pretty printing JSON strings for PHP < 5.4

License

Notifications You must be signed in to change notification settings

markenwerk/php-json-pretty-printer

Repository files navigation

PHP JSON Pretty Printer

Build Status Test Coverage Dependency Status SensioLabs Insight Code Climate Latest Stable Version Total Downloads License

A PHP library providing pretty printing JSON strings for PHP < 5.4 based upon this StackOverflow answer by Kendall Hopkins.

Installation

{
   	"require": {
        "markenwerk/json-pretty-printer": "~1.0"
    }
}

Usage

Autoloading and namesapce

require_once('path/to/vendor/autoload.php');

Pretty printing a JSON string

Default indentation is one tab.

use Markenwerk\JsonPrettyPrinter;

$jsonString = json_encode($myObject);
$prettyPrinter = new JsonPrettyPrinter\JsonPrettyPrinter();
$prettyPrinted = $prettyPrinter
	->setIndentationString('  ')
	->prettyPrint($jsonString);

Contribution

Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.

License

PHP JSON Pretty Printer is under the MIT license.