root23 / php-json-canonicalization
此包最新版本(1.0.1)没有提供许可证信息。
基于RFC-8785,以规范方式序列化数据。
1.0.1
2023-09-27 08:27 UTC
Requires
- php: >=8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.27.0
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^9
README
基于RFC-8785,以规范方式序列化数据。
RFC-8785 - https://tools.ietf.org/html/rfc8785
灵感来源于 https://github.com/aywan/php-json-canonicalization & https://github.com/cyberphone
安装
composer require root23/php-json-canonicalizator
使用
$canonicalizator = JsonCanonicalizatorFactory::getInstance();
$canonicalizedJsonString = $canonicalizator->canonicalize($input, false);
$canonicalizedJsonString = $canonicalizator->canonicalize($input, true); // hex
示例输入
{
"numbers": [333333333.33333329, 1E30, 4.50, 2e-3, 0.000000000000000000000000001],
"string": "\u20ac$\u000F\u000aA'\u0042\u0022\u005c\\\"\/",
"literals": [null, true, false]
}
输出
{"literals":[null,true,false],"numbers":[333333333.3333333,1e+30,4.5,0.002,1e-27],"string":"€$\u000f\nA'B\"\\\\\"/"}
十六进制输出
7b 22 6c 69 74 65 72 61 6c 73 22 3a 5b 6e 75 6c 6c 2c 74 72 75 65 2c 66 61 6c 73 65 5d 2c 22 6e
75 6d 62 65 72 73 22 3a 5b 33 33 33 33 33 33 33 33 33 2e 33 33 33 33 33 33 33 2c 31 65 2b 33 30
2c 34 2e 35 2c 30 2e 30 30 32 2c 31 65 2d 32 37 5d 2c 22 73 74 72 69 6e 67 22 3a 22 e2 82 ac 24
5c 75 30 30 30 66 5c 6e 41 27 42 5c 22 5c 5c 5c 5c 5c 22 2f 22 7d