#json #serde-json #规范 #序列化 #serde

json-canon

将JSON序列化为规范格式

4个版本

0.1.3 2023年5月13日
0.1.2 2023年5月12日
0.1.1 2023年5月11日
0.1.0 2023年5月11日

#871 in 编码

Download history 49/week @ 2024-04-03 98/week @ 2024-04-10 66/week @ 2024-04-17 55/week @ 2024-04-24 68/week @ 2024-05-01 92/week @ 2024-05-08 83/week @ 2024-05-15 267/week @ 2024-05-22 273/week @ 2024-05-29 212/week @ 2024-06-05 43/week @ 2024-06-12 48/week @ 2024-06-19 71/week @ 2024-06-26 70/week @ 2024-07-03 87/week @ 2024-07-10 145/week @ 2024-07-17

每月380次下载

Apache-2.0

30KB
679

json-canon

Crates.io version Download docs.rs docs

将JSON序列化为规范格式。

安装

cargo add json-canon

示例

use json_canon::to_string;
use serde_json::json;

let data = json!({
    "from_account": "543 232 625-3",
    "to_account": "321 567 636-4",
    "amount": 500,
    "currency": "USD"
});

println!("{}", to_string(&data)?);
// {"amount":500,"currency":"USD","from_account":"543 232 625-3","to_account":"321 567 636-4"}

查看 ./examples/basic.rs

使用方法

查看 文档

注意事项

JavaScript实现不同,serde_jsonf64::NANf64::Infinite 反序列化为 None,因此如果给定一个包含这些值的Rust结构体,当前的 json-canon 序列化器将输出 ""null"

基准测试

from_elem/basic/[{"_id":"59ef4a83ee8364808d761beb","about":"Nisi reprehenderit nulla ad officia pari...
                        time:   [28.019 µs 28.032 µs 28.047 µs]
                        thrpt:  [35.654 Kelem/s 35.673 Kelem/s 35.690 Kelem/s]

许可证

Copyright 2023 Michael Williams

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

依赖项

~0.5–1MB
~20K SLoC