localheinz/json-printer

该包已被废弃且不再维护。作者建议使用 ergebnis/json-printer 包。

提供JSON打印器,支持灵活的缩进。

3.5.0 2024-01-29 15:33 UTC

README

Integrate Merge Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads Monthly Downloads

本项目提供了一个具有JSON打印器的 composer 包,支持灵活的缩进。

安装

运行

composer require ergebnis/json-printer

使用

假设我们有一个变量 $json,它包含一些未缩进的JSON

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

或缩进为4个空格

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

但我们需要使用2个空格(或制表符)缩进。

这就是 Ergebnis\Json\Printer\Printer 的作用

<?php

declare(strict_types=1);

use Ergebnis\Json\Printer;

$printer = new Printer\Printer();

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

结果为 $printed

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

💡 注意,该打印器只关注规范缩进,不进行转义或反转义。

变更日志

本项目维护者将本项目的重要变更记录在 变更日志 中。

贡献

本项目维护者建议遵循 贡献指南

行为准则

本项目维护者要求贡献者遵循 行为准则

一般支持策略

本项目维护者提供有限的支持。

您可以通过 赞助 @localheinz申请与本项目相关的服务发票 来支持本项目的维护。

PHP版本支持策略

本项目支持具有 活跃和安全支持 的PHP版本。

本项目维护者在其初始发布后添加对PHP版本的支持,并在其达到安全支持结束时停止对该PHP版本的支持。

安全策略

本项目有一个 安全策略

许可证

本项目使用 MIT许可证

致谢

PrinterComposer\Json\JsonFormatter(最初由 Nils AdermannJordi Boggiano 以MIT许可证发布)采纳,他们又从 Dave Perrett的博客文章(最初由 Dave Perrett 以MIT许可证发布)中采纳。

PrinterTestComposer\Test\Json\JsonFormatterTest(最初由Nils AdermannJordi Boggiano许可,使用MIT协议)以及ZendTest\Json\JsonTest(最初使用新BSD许可证)的启发。

社交

在Twitter上关注@localheinz@ergebnis