Expand description
§Jsony
An ergonomic and performant (at runtime & compile time) serialization framework for the following formats:
- JSON (with optional extensions: trailing commas, comments, unquoted keys)
- Custom Binary Encoding
§Decoding/Encoding JSON with strongly typed data structures
The Jsony derive macro can automatically implement the encoding and decoding for a number of formats.
use jsony::Jsony;
#[derive(Jsony)]
#[jsony(Json)]
struct Player {
name: String,
health: u32,
inventory: Vec<String>
}
fn main() -> Result<(), jsony::JsonError> {
let input: String = jsony::object!{
name: "Jimmy",
health: 100,
inventory: [
"Rock",
"Helmet"
]
};
let mut player: Player = jsony::from_json(&input)?;
player.health -= 10;
let output: String = jsony::to_json(&player);
println!("generated json:\n {}", output);
Ok(())
}
Here we choose to implement ToJson
and FromJson
automatically via the Json
attribute.
When deriving a format trait, all fields in the struct/enum need to implement the same trait or have an implementation specified by a field attribute.
§Feature Documentation
- Jsony derive macro: Declaratively specify how your Rust types map to various formats.
- Flexible JSON decoder: Enable extensions for comments, trailing comments and more.
- JSON template macros: Flexibly generate a JSON string directly.
- Binary format: Encode data in a fast, compact binary representation.
- Lazy JSON Parsing: Dynamically parse only what you need.
- Flexible encode destination: Encode to a file or stack-allocating buffer.
Modules§
- binary
- Binary encoding module for jsony.
- error
- Error definitions
- helper
- json
- Lower level JSON utilities and definitions
- parser
- text
Macros§
Structs§
- Bytes
Writer - An optimized output buffer with dynamic backing storage.
- Json
Error - The error type for JSON decoding failure with context.
- Json
Parser Config - Configuration options for the JSON parser.
- Maybe
Json - Either a JSON string slice or an error state.
- RawJson
- A validated JSON string slice.
- Text
Writer - A UTF-8 wrapper around a BytesWriter.
Traits§
- From
Binary - A trait for parsing a value from a compact binary representation.
- From
Json - A trait for types that can be parsed from JSON.
- Into
Byte Writer - Conversion into a
ByteWriter
with content extraction. - Into
Text Writer - Conversion into a
TextWriter
with content extraction. - ToBinary
- A trait for converting a value to a compact binary representation.
- ToJson
- A trait for converting a value into JSON.
Functions§
- drill
- Lazy JSON parser
- from_
binary - from_
json - Parses a value implementing
FromJson
from a JSON string. - from_
json_ bytes - Parses a value implementing
FromJson
from a byte of slice of JSON. - from_
json_ with_ config - Parses a value implementing
FromJson
from a string with a custom parser configuration. - to_
binary - to_
binary_ into - to_json
- Converts the given value into a JSON string representation.
- to_
json_ into - Converts the given value into a JSON string appending it to the provided output.
Derive Macros§
- Jsony
- Unified derive macro for implementing various conversion traits