deser-json
JSON support for
deser. Use it to read and write JSON
for any type that implements deser's Serialize and Deserialize.
use ;
let json = r#"{
"kind": "upload",
"id": 340282366920938463463374607431768211455,
"payload": "aGVsbG8="
}"#;
let event: Event = from_str.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Why use it:
- No dependencies besides
deserby default. Thespeedupsfeature pulls inzmijandsimdutf8for faster float formatting and UTF-8 validation. - Borrowing: strings without escapes are passed on borrowed so types
can hold
&strpointing into the input. - Numbers without loss: 128 bit integers are written and read as
numbers, and with
DeserializerConfig::exact_numbersdecimals such as0.10keep their exact text for types likerust_decimal::Decimal. - Bytes:
Vec<u8>is base64 by default and can be configured per format or per field (hex, arrays of integers, ...). - Unlimited nesting: a million nested arrays do not overflow the stack.
- JSON Lines: a
Deserializercan read one value per line and recovers from errors in individual lines, aSerializerwrites them. - Streams:
from_readerandto_writerwork withstd::io, and the configurations read and write streams of values (JSON Lines or concatenated JSON) withdeser::ioor async runtimes (deser-tokio). Values are parsed while their input arrives, so only incomplete tokens are buffered, and written while they are serialized. - Source locations: errors carry line and column and with
DeserializerConfig::track_locationsvalues can be wrapped indeser_location::Spannedto learn where they came from.