Fast json encoder in rust, that does more at compile time, and less at run time. One notable feature is the ability to encode the structure of JSON objects in their type.
This allows for a very compact representation of objects in memory, and up to an order of magnitude better performance
than the traditional approach (used by serde's json!
marco, for instance) where JSON objects are stored as HashMaps.
```rust extern crate jsonintype;
use jsonintype::*;
fn main() { let void = (); let list = jsonlist![1,2,3]; let dynamickey = "hello";
let json_val = JSON(json_object!{
void, list,
[dynamic_key]: "world"
});
/* The type of json_val is:
json_in_type::JSON<
main::InlinedJSONObjectEntry<
(),
main::InlinedJSONObjectEntry<
json_in_type::JSONListElem<{integer},
json_in_type::JSONListElem<{integer},
json_in_type::JSONListElem<{integer},
json_in_type::JSONListEnd>>>,
json_in_type::JSONObjectEntry<
&str, &str,
json_in_type::JSONObjectEnd>>>>
*/
assert_eq!(
r#"{"void":null,"list":[1,2,3],"hello":"world"}"#,
format!("{}", json_val)
);
} ```
This library is generally faster than SERDE. Here are detailed comparison results on different json serialization tasks realized on an AMD Ryzen 5 1600X. See detailed benchmark results.
json
{"nested":{"nested":{"nested":{"nested":{"nested":{"nested":{"nested":{"nested":{"value":n}}}}}}}}}
json
{
"void": null,
"list": [1, 2, 3, 3],
"hello": "world"
}
#[derive(...)]
json
{
"void": null,
"list": [1, 2, 3, 3],
"hello": "world"
}
created from the following rust struct
```rust
struct MyObject {
void: (),
list: Vec