4 releases

0.1.3 May 13, 2023
0.1.2 May 12, 2023
0.1.1 May 11, 2023
0.1.0 May 11, 2023

#761 in Encoding

Download history 18/week @ 2024-01-29 9/week @ 2024-02-26 2/week @ 2024-03-04 9/week @ 2024-03-11 110/week @ 2024-04-01

119 downloads per month

Apache-2.0

30KB
679 lines

json-canon

Crates.io version Download docs.rs docs

Serialize JSON into a canonical format.

Install

cargo add json-canon

Example

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"}

See ./examples/basic.rs

Usage

See docs

Caveats

Different from the JavaScript implementation, serde_json deserializes f64::NAN and f64::Infinite as None, so if given a Rust struct with these values, the json-canon serializer will currently output "null".

Bench

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]

License

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.

Dependencies

~0.5–1MB
~20K SLoC