json_in_type
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.
Exemple use
extern crate json_in_type;
use *;
Performance
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.
Encoding 8 nested json objects using a rust macro
We use serde's
json!
and json_in_type's
json_object
macro to encode a nested json object.
Encoded object
We encode a JSON structure composed of 8 nested objects, each of which contains a single key, that is known at compile time. The last nested object contains an integer n that is not known at compile time.
Benchmark result
Encoding a very simple json object using a rust macro
Encoded object
Benchmark result
Encoding a very simple json object using #[derive(...)]
Encoded object
created from the following rust struct
Benchmark result
External links
- docs.rs hosts this crate's api documentation.
- documentation for the
json_object!
macro - documentation for the
JSONValue
trait
- documentation for the
- You can see json_in_type on crates.io.