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
186 downloads per month
Used in jsony_config
250KB
6K
SLoC
Jsony
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.
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