localheinz / json-printer
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- ergebnis/data-provider: ^3.2.0
- ergebnis/license: ^2.4.0
- ergebnis/php-cs-fixer-config: ^6.20.0
- ergebnis/phpunit-slow-test-detector: ^2.9.0
- fakerphp/faker: ^1.23.1
- infection/infection: ~0.26.6
- phpunit/phpunit: ^9.6.16
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.19.2
- vimeo/psalm: ^5.20.0
This package is auto-updated.
Last update: 2024-09-10 08:13:08 UTC
README
本项目提供了一个具有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许可证。
致谢
Printer
从 Composer\Json\JsonFormatter
(最初由 Nils Adermann 和 Jordi Boggiano 以MIT许可证发布)采纳,他们又从 Dave Perrett的博客文章(最初由 Dave Perrett 以MIT许可证发布)中采纳。
PrinterTest
受Composer\Test\Json\JsonFormatterTest
(最初由Nils Adermann和Jordi Boggiano许可,使用MIT协议)以及ZendTest\Json\JsonTest
(最初使用新BSD许可证)的启发。
社交
在Twitter上关注@localheinz和@ergebnis。