Crate jsony

Source
Expand description

§Jsony

An ergonomic and performant (at runtime & compile time) serialization framework for the following formats:

§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

Modules§

binary
Binary encoding module for jsony.
error
Error definitions
helper
json
Lower level JSON utilities and definitions
parser
text

Macros§

array
Templating macro for creating JSON Arrays
object
Templating macro for creating JSON objects

Structs§

BytesWriter
An optimized output buffer with dynamic backing storage.
JsonError
The error type for JSON decoding failure with context.
JsonParserConfig
Configuration options for the JSON parser.
MaybeJson
Either a JSON string slice or an error state.
RawJson
A validated JSON string slice.
TextWriter
A UTF-8 wrapper around a BytesWriter.

Traits§

FromBinary
A trait for parsing a value from a compact binary representation.
FromJson
A trait for types that can be parsed from JSON.
IntoByteWriter
Conversion into a ByteWriter with content extraction.
IntoTextWriter
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