Expand description
jzon — purpose-built, zero-copy JSON serialization for specific structs.
§Design
Use #[derive(ToJson, FromJson)] to generate a monomorphised JSON
(de)serializer for each of your types at compile time. No generic visitor
indirection, no intermediate Value allocation, no format-string overhead.
§Cargo features
| Feature | Default | Effect |
|---|---|---|
derive | ✓ | #[derive(ToJson, FromJson)] proc-macros |
simd | u128 SWAR scanning (16 B/iter) | |
simd + unstable | std::simd portable SIMD (32–64 B/iter, nightly) | |
fast-float | ryu serialization, fast_float2 parsing | |
stats | ScannerStats allocation/cache-hit counters |
For serde integration see jzon-rs-serde.
For a serde_json drop-in see jzon-rs-compat.
§Zero-copy deserialization
Fields typed &'de str borrow directly from the input — no String is
allocated unless the JSON string contains escape sequences.
§Field-hint cache
The generated FromJson impl maintains a one-word field-hint variable
that predicts which field key to expect next. For JSON whose field order
matches the struct definition — the common case — almost every key dispatch
is O(1) without hashing.
§Safe Rust only
There are no unsafe blocks in this crate. All SIMD scanning uses
std::simd (nightly) or pure u64/u128 arithmetic (SWAR).
§Quick start
use jzon::{ToJson, FromJson};
#[derive(ToJson, FromJson, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
struct User<'a> {
user_id: u64,
name: &'a str,
#[serde(skip_serializing_if = "Option::is_none")]
email: Option<String>,
#[serde(default)]
score: f64,
}
let input = r#"{"userId":1,"name":"alice","score":9.5}"#;
let user: User = User::from_json_str(input).unwrap();
let out = user.to_json_string();Re-exports§
pub use error::Error;pub use scanner::JsonStr;pub use scanner::Scanner;pub use ser::ToJson;pub use de::FromJson;pub use fixed::FixedBuf;pub use fixed::ToJsonExt;pub use fixed::json_str_len;
Modules§
- de
FromJson<'de>trait and primitive implementations.- error
- fixed
- Zero-allocation, stack-based JSON output via const-generic fixed buffers.
- scanner
- ser
ToJsontrait and primitive implementations.- simd