colinodell/json5
Composer 安装命令:
composer require colinodell/json5
包简介
UTF-8 compatible JSON5 parser for PHP
README 文档
README
This library is a PHP fork of the JSON5 reference implementation.
JSON5 is a JS-compatible extension to JSON which allows comments, trailing commas, single-quoted strings, and more:
{ foo: 'bar', while: true, this: 'is a \ multi-line string', // this is an inline comment here: 'is another', // inline comment /* this is a block comment that continues on another line */ hex: 0xDEADbeef, half: .5, delta: +10, to: Infinity, // and beyond! finally: [ 'some trailing commas', ], }
See the JSON5 website for additional examples and details.
Install
Via Composer
composer require colinodell/json5
Usage
This package adds a json5_decode() function which is a drop-in replacement for PHP's built-in json_decode():
$json = file_get_contents('foo.json5'); $data = json5_decode($json);
It takes the same exact parameters in the same order. For more details on these, see the PHP docs.
To achieve the best possible performance, it'll try parsing with PHP's native function (which usually fails fast) and then falls back to JSON5.
Exceptions
This function will always throw a SyntaxError exception if parsing fails. This is a subclass of the new \JsonException introduced in PHP 7.3.
Providing or omitting the JSON_THROW_ON_ERROR option will have no effect on this behavior.
Binary / Executable
A binary/executable named json5 is also provided for converting JSON5 to plain JSON via your terminal.
Usage: json5 [OPTIONS] [FILE]
-h, --help Shows help and usage information
(Reading data from STDIN is not currently supported on Windows)
Examples:
Converting a file named file.json5:
json5 file.json5
Converting a file and saving its output:
json5 file.json5 > file.json
Converting from STDIN:
echo -e "{hello: 'world!'}" | json5
Converting from STDIN and saving the output:
echo -e "{hello: 'world!'}" | json5 > output.json
Change log
Please see CHANGELOG for more information on what has changed recently.
Testing
composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email colinodell@gmail.com instead of using the issue tracker.
Support
In addition to standard support, consider a Tidelift Subscription for professional support and get alerted when new releases or security issues come out.
Credits
- Colin O'Dell
- Aseem Kishore, the JSON5 project, and their contributors
- All other contributors to this project
License
The MIT License (MIT). Please see License File for more information.
colinodell/json5 适用场景与选型建议
colinodell/json5 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.29M 次下载、GitHub Stars 达 304, 最近一次更新时间为 2017 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「json_decode」 「JSON5」 「json5_decode」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 colinodell/json5 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 colinodell/json5 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 colinodell/json5 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
☯ Insightful PHP debugging assistant.
☯ Insightful PHP debugging assistant.
A Simple wrapper of json_decode() and json_encode(). This provides object-oriented interface and exception-based error handing.
Kinikit - PHP Application development framework MVC component
ext-json wrapper with sane defaults
A package to cast json fields, each sub-keys is castable
统计信息
- 总下载量: 25.29M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 311
- 点击次数: 25
- 依赖项目数: 49
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-10