#json #json-parser #serialization

jsony

An experimental fast compiling serialization and deserialization libary for JSON like formats

10 releases

0.1.7 Jun 25, 2025
0.1.6 Jun 8, 2025
0.1.5 May 28, 2025
0.1.3 Apr 24, 2025
0.0.1 Oct 1, 2024

#667 in Encoding

Download history 255/week @ 2025-03-28 169/week @ 2025-04-04 68/week @ 2025-04-11 108/week @ 2025-04-18 55/week @ 2025-04-25 123/week @ 2025-05-02 108/week @ 2025-05-09 28/week @ 2025-05-16 122/week @ 2025-05-23 38/week @ 2025-05-30 120/week @ 2025-06-06 16/week @ 2025-06-13 123/week @ 2025-06-20 41/week @ 2025-06-27 4/week @ 2025-07-04

186 downloads per month
Used in jsony_config

MIT license

250KB
6K SLoC

Jsony

An experimental fast compiling serialization and deserialization rust library for JSON like formats.

Crates.io Crates.io License

WARNING: Jsony is currently in early development and makes extensive use of unsafe.

Features

  • Fast compile times
  • Competitive runtime performance
  • Featureful derive macros for implementing To/From for various data formats
  • Infallible serialization guaranteed to succeed via the type system
  • Data formats:
    • JSON (optional extension: trailing commas, comments, unquoted keys)
    • Compact Binary Encoding with zerocopy and versioning support.
  • Lazy JSON parser for efficiently extracting small fragments.
  • JSON templating macros
  • Encode directly to a file or stack allocated to buffer.
  • Custom field property validation

Example

use jsony::{Jsony, require};

#[derive(Jsony, Debug)]
#[jsony(Json, tag = "kind")]
enum Status<'a> {
    Online,
    Error {
        #[jsony(default = i64::MAX)]
        code: i64,
        #[jsony(validate = require!(|m| !m.is_empty(), "Message must be non-empty"))]
        message: Cow<'a, str>,
        #[jsony(flatten, via = Iterator)]
        properties: Vec<(String, Data)>,
    },
    Offline,
}

#[derive(Jsony, Debug)]
#[jsony(Json, untagged)]
enum Data {
    Text(String),
    Array(Vec<Data>),
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let input: String = jsony::object! {
        kind: "Error",
        code: 300,
        message: "System Failure",
        value: ["alpha", ["beta", "bravo"]],
    };

    let data: String = jsony::drill(&input)["value"][1][0].parse()?;
    assert_eq!(data, "beta");

    let status: Status = jsony::from_json(&input)?;

    assert_eq!(input, jsony::to_json(&status));

    Ok(())
}

Acknowledgements

The derive feature set is largely based of serde and serde_with.
The json parser is heavily inspire by jiter and serde_json.

Dependencies

~135KB