Crates.io | jsony |
lib.rs | jsony |
version | 0.0.2 |
source | src |
created_at | 2024-10-01 11:53:49.052484 |
updated_at | 2024-11-03 20:25:30.418158 |
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 | 246,386 |
An experimental fast compiling serialization and deserialization rust libary for JSON like formats.
WARNING: Jsony is currently only a prototype, makes extensive use of unsafe and lacks extensive testing. It is not recommended to be used for external facing systems at this time.
use jsony::Jsony;
#[derive(Jsony, Debug)]
#[jsony(FromJson, ToJson, tag = "kind")]
enum Status<'a> {
Online,
Error {
#[jsony(default = i64::MAX)]
code: i64,
message: Cow<'a, str>,
#[jsony(flatten, via = Iterator)]
properties: Vec<(String, JsonItem<'a>)>,
},
Offline,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let input: String = jsony::object! {
kind: "Error",
code: 300,
message: "System Failure",
data: [1, 2, 3],
value: {
previous: {
kind: "Offline",
}
}
};
let previous: Status = jsony::drill(&input)["value"]["previous"].parse()?;
assert!(matches!(previous, Status::Offline));
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
.