PHPackages                             ergebnis/json-printer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ergebnis/json-printer

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ergebnis/json-printer
=====================

Provides a JSON printer, allowing for flexible indentation.

3.8.1(8mo ago)9138.2M—6.3%2[6 PRs](https://github.com/ergebnis/json-printer/pulls)19MITPHPPHP ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jan 5Pushed 4w ago2 watchersCompare

[ Source](https://github.com/ergebnis/json-printer)[ Packagist](https://packagist.org/packages/ergebnis/json-printer)[ Docs](https://github.com/ergebnis/json-printer)[ RSS](/packages/ergebnis-json-printer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (25)Used By (19)

json-printer
============

[](#json-printer)

[![Integrate](https://github.com/ergebnis/json-printer/workflows/Integrate/badge.svg)](https://github.com/ergebnis/json-printer/actions)[![Merge](https://github.com/ergebnis/json-printer/workflows/Merge/badge.svg)](https://github.com/ergebnis/json-printer/actions)[![Release](https://github.com/ergebnis/json-printer/workflows/Release/badge.svg)](https://github.com/ergebnis/json-printer/actions)[![Renew](https://github.com/ergebnis/json-printer/workflows/Renew/badge.svg)](https://github.com/ergebnis/json-printer/actions)

[![Code Coverage](https://camo.githubusercontent.com/cc432e2d1acb42c30ab655464f09f5b33453f17fe0897eb97f3f267c67c1e45d/68747470733a2f2f636f6465636f762e696f2f67682f65726765626e69732f6a736f6e2d7072696e7465722f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ergebnis/json-printer)

[![Latest Stable Version](https://camo.githubusercontent.com/78b226257ffa74ab4b21d75da15af36830dd667762b239551cf5d9a2c1adf6e1/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f6a736f6e2d7072696e7465722f762f737461626c65)](https://packagist.org/packages/ergebnis/json-printer)[![Total Downloads](https://camo.githubusercontent.com/7dc12e0412144b9870bc5ad689a11ef5ef1d05142e17bab7d4128784d2a24385/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f6a736f6e2d7072696e7465722f646f776e6c6f616473)](https://packagist.org/packages/ergebnis/json-printer)[![Monthly Downloads](https://camo.githubusercontent.com/e7adc2244f02905722b409cfaa9f07dd92d6d708754f39135b49115cba5bba85/687474703a2f2f706f7365722e707567782e6f72672f65726765626e69732f6a736f6e2d7072696e7465722f642f6d6f6e74686c79)](https://packagist.org/packages/ergebnis/json-printer)

This project provides a [`composer`](https://getcomposer.org) package with a JSON printer, allowing for flexible indentation.

Installation
------------

[](#installation)

Run

```
composer require ergebnis/json-printer
```

Usage
-----

[](#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

```
