jzon-rs
Zero-copy JSON for Rust with compile-time generated parsers.
Quick Start
[]
= "0.1"
use ;
Optional features
| Feature | What it adds |
|---|---|
serde |
jzon::from_str / to_string for any serde-deriving type |
compat |
jzon::compat — serde_json-compatible API (Value, json!, etc.) |
simd |
u128 SWAR scanning (16 bytes/iter) |
fast-float |
ryu float serialization, fast_float2 parsing |
unstable |
std::simd portable SIMD 32–64 bytes/iter (nightly only) |
stats |
Allocation counters on Scanner |
Using the serde feature
[]
= { = "0.1", = ["serde"] }
= { = "1", = ["derive"] }
use ;
let user: User = from_str.unwrap;
let out = to_string.unwrap;
Using the compat feature
[]
= { = "0.1", = ["compat"] }
use compat as serde_json; // hot-path via jzon, types from serde_json
let user: User = from_str.unwrap;
let v: Value = from_str.unwrap;
Highlights
- Zero-copy —
&'a strfields borrow directly from the input; no heap allocation for string data. - SIMD scanning — vectorised byte-search on x86-64 and aarch64 for structural character detection.
- No
unsafein user code — the derive macros emit fully safe Rust. - serde attribute compatibility —
#[serde(rename = "…")],#[serde(skip_serializing_if)], etc. are honoured by the derive macros.
Performance
Apple M2, --features simd,fast-float, criterion 0.5.
| Dataset | jzon/A | serde_json | sonic-rs |
|---|---|---|---|
| twitter de | 360 µs | 354 µs | 365 µs |
| canada de | ★ 2.66 ms | 3.80 ms | 3.32 ms |
| citm_catalog de | ★ 589 µs | 1.02 ms | 837 µs |
| micro Point de | ★ 47 ns | 83 ns | 71 ns |
| micro Record de | ★ 81 ns | 92 ns | 102 ns |
| twitter ser | ★ 11.3 µs | 31.6 µs | 11.5 µs |
| micro Record ser | ★ 52 ns | 69 ns | 61 ns |
Other Crates
| Crate | Purpose |
|---|---|
jzon-rs-serde |
Standalone serde Serializer/Deserializer (included via serde feature) |
jzon-rs-compat |
Cargo [patch] to replace serde_json for the whole dep tree |
License
MIT
Made with ❤️ by Rajaniraiyn