8ctopus / relaxed-json
厌倦了JSON严格的语法吗?那么relaxed JSON正适合你。
1.0.2
2023-12-28 11:18 UTC
Requires
- php: >=7.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- nunomaduro/collision: ^5.0|^6.0
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9|^10
This package is auto-updated.
Last update: 2024-08-26 14:39:26 UTC
README
厌倦了JSON严格的语法吗?那么relaxed JSON正适合你。
特性
- 支持所有形式的注释
// 我的注释
,/* 我的注释 */
- 忽略数组或对象末尾的逗号
- 当JSON无效时抛出异常
- 零依赖
安装
composer require 8ctopus/relaxed-json
使用
use Oct8pus\RelaxedJson; $json = <<<JSON { // maximum requests per hour "throttleThreshold": 300, } JSON; var_dump(RelaxedJson::decode($json, true));
array(1) { 'name' => string(20) "8ctopus/relaxed-json" }
异常
$json = <<<JSON { "throttleThreshold" => 300, } JSON; // throws RelaxedJsonException Syntax error RelaxedJson::decode($json, true);
致谢
此库是对来自https://github.com/etconsilium/php-json-fix的原始工作的改进重新打包
测试
composer test
整洁的代码
composer fix
composer fix-risky