Crates.io | jsode |
lib.rs | jsode |
version | 0.2.0 |
source | src |
created_at | 2024-04-16 14:28:30.355092 |
updated_at | 2024-05-19 07:19:57.954998 |
description | Simple, zero-copy & zero-dependency JSON Parser |
homepage | |
repository | https://github.com/taminhtienhai/jsode |
max_upload_size | |
id | 1210319 |
size | 787,761 |
[!WARNING] This project is under heavy development which contain bugs and unresolve issues. Please consider when using it for prouduction.
Simple, zero-copy & zero-dependency JSON Parser
cargo add jsode
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(())
}
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(())
}
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(())
}