定制 ergebnis/json-printer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ergebnis/json-printer

最新稳定版本:3.8.1

Composer 安装命令:

composer require ergebnis/json-printer

包简介

Provides a JSON printer, allowing for flexible indentation.

README 文档

README

Integrate Merge Release Renew

Code Coverage

Latest Stable Version Total Downloads Monthly Downloads

This project provides a composer package with 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

<?php

declare(strict_types=1);

use Ergebnis\Json\Printer;

$printer = new Printer\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

The maintainers of this project record notable changes to this project in a changelog.

Contributing

The maintainers of this project suggest following the contribution guide.

Code of Conduct

The maintainers of this project ask contributors to follow the code of conduct.

General Support Policy

The maintainers of this project provide limited support.

You can support the maintenance of this project by sponsoring @ergebnis.

PHP Version Support Policy

This project supports PHP versions with active and security support.

The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.

Security Policy

This project has a security policy.

License

This project uses the MIT license.

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).

Social

Follow @localheinz and @ergebnis on Twitter.

统计信息

  • 总下载量: 35M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 91
  • 点击次数: 1
  • 依赖项目数: 19
  • 推荐数: 0

GitHub 信息

  • Stars: 90
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04