rector/vendor/ergebnis/json-printer
Tomas Votruba 992aade98a Updated Rector to commit d89c23267c
d89c23267c [automated] Re-Generate Nodes/Rectors Documentation (#2262)
2022-05-08 00:33:36 +00:00
..
src Updated Rector to commit d89c23267c 2022-05-08 00:33:36 +00:00
CHANGELOG.md Updated Rector to commit 35ef77b4f2 2021-12-27 15:34:11 +00:00
composer.json Updated Rector to commit d89c23267c 2022-05-08 00:33:36 +00:00
composer.lock Updated Rector to commit 35ef77b4f2 2021-12-27 15:34:11 +00:00
LICENSE.md Updated Rector to commit 35ef77b4f2 2021-12-27 15:34:11 +00:00
README.md Updated Rector to commit 35ef77b4f2 2021-12-27 15:34:11 +00:00

json-printer

Integrate Merge Prune Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads

Provides a JSON printer, allowing for flexible indentation.

Installation

Run

$ composer require ergebnis/json-printer

Usage

Let's assume we have a variable $json which contains some JSON that is not indented:

{"name":"Andreas Möller","emoji":"🤓","urls":["https://localheinz.com","https://github.com/localheinz","https://twitter.com/localheinz"]}

or indented with 4 spaces:

{
    "name":"Andreas Möller",
    "emoji":"🤓",
    "urls":[
        "https://localheinz.com",
        "https://github.com/localheinz",
        "https://twitter.com/localheinz"
    ]
}

but we want to indent it with 2 spaces (or tabs).

This is where Ergebnis\Json\Printer\Printer comes in

use Ergebnis\Json\Printer\Printer;

$printer = new Printer();

$printed = $printer->print(
    $json,
    '  '
);

which results in $printed:

{
  "name":"Andreas Möller",
  "emoji":"🤓",
  "urls":[
    "https://localheinz.com",
    "https://github.com/localheinz",
    "https://twitter.com/localheinz"
  ]
}

💡 Note that this printer is only concerned with normalizing the indentation, no escaping or un-escaping occurs.

Changelog

Please have a look at CHANGELOG.md.

Contributing

Please have a look at CONTRIBUTING.md.

Code of Conduct

Please have a look at CODE_OF_CONDUCT.md.

License

This package is licensed using the MIT License.

Please have a look at LICENSE.md.

Credits

The Printer is adopted from Composer\Json\JsonFormatter (originally licensed under MIT by Nils Adermann and Jordi Boggiano), who adopted it from a blog post by Dave Perrett (originally licensed under MIT by Dave Perrett).

The PrinterTest is inspired by Composer\Test\Json\JsonFormatterTest (originally licensed under MIT by Nils Adermann and Jordi Boggiano), as well as ZendTest\Json\JsonTest (originally licensed under New BSD License).

Curious what I am building?

📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.