jzon-rs
Zero-copy JSON for Rust with compile-time generated parsers.
Quick Start
[]
= "0.2"
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 |
zmij-float-ser |
Use zmij (Schubfach + yy_double) for float serialization instead of ryu. See "Float serialization backend" below for tradeoffs. MSRV 1.71. |
unstable |
std::simd portable SIMD 32–64 bytes/iter (nightly only) |
stats |
Allocation counters on Scanner |
Float serialization backend
zmij-float-ser swaps ryu for zmij. Wins ~30% on Linux, loses ~10% on Apple Silicon — see #3 for numbers.
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
Up to 3.6× serde_json, 2.4× sonic-rs, 7.8× simd-json.
Top: 53.6 GiB/s twitter serialize on Apple Silicon.
Full matrix: BENCHMARKS.md.
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