Crates.io | jsony |
lib.rs | jsony |
version | 0.1.7 |
created_at | 2024-10-01 11:53:49.052484+00 |
updated_at | 2025-06-25 13:13:56.968764+00 |
description | An experimental fast compiling serialization and deserialization libary for JSON like formats. |
homepage | |
repository | https://github.com/exrok/jsony |
max_upload_size | |
id | 1392815 |
size | 305,138 |
An experimental fast compiling serialization and deserialization rust library for JSON like formats.
WARNING: Jsony is currently in early development and makes extensive use of unsafe.
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(())
}
The derive feature set is largely based of serde
and serde_with
.
The json parser is heavily inspire by jiter
and serde_json
.