5 releases
0.2.0 | May 19, 2024 |
---|---|
0.1.3 | Apr 16, 2024 |
0.1.2 | Apr 16, 2024 |
0.1.1 | Apr 16, 2024 |
0.1.0 | Apr 16, 2024 |
#1319 in Parser implementations
248 downloads per month
105KB
1.5K
SLoC
JSON ❤️ Oxide = Jsode
[!WARNING] This project is under heavy development which contain bugs and unresolve issues. Please consider when using it for prouduction.
Overview
Simple, zero-copy & zero-dependency JSON Parser
Install
cargo add jsode
Getting Started
1. Index JSON key
use jsode::prelude::*;
fn main() -> jsode::Result<()> {
let mut src = JsonParser::new("{ 'hello': 'world' }");
let ast = src.parse()?;
assert!(ast.index("hello").is_some());
assert!(ast.index("none_exist_key").is_none());
Ok(())
}
2. Getting/Deserialize single JSON's property
use jsode::prelude::*;
fn main() -> jsode::Result<()> {
let mut src = JsonParser::new("{ 'hello': 'world' }");
let ast = src.parse()?;
assert_eq!("world", ast.index("hello").unwrap().parse_into::<String>()?);
Ok(())
}
3. Deserialize into struct
use jsode::prelude::*;
#[derive(Deserialize, PartialEq, Debug)]
struct Color {
#[prop = "r"]
red: u8,
#[prop = "b"]
blue: u8,
green: u8,
}
fn main() -> jsode::Result<()> {
let mut src = JsonParser::new(r#"{
'r': 255,
'b': 96,
'green': 0,
}"#);
let ast = src.parse()?;
let expected = Color {
red: 255,
blue: 96,
green: 0,
};
assert_eq!(expected, ast.parse_into::<Color>()?);
Ok(())
}
Dependencies
~225–660KB
~16K SLoC