tinyjson

version CI

tinyjson is a library to parse/generate JSON format document.

Goals of this library are

Documentation

Requirements

Rust stable toolchain.

Installation

Add this crate to dependencies section of your Cargo.toml

toml [dependencies] tinyjson = "2"

Example

```rust use tinyjson::JsonValue; use std::collections::HashMap; use std::convert::TryInto;

let s = r#" { "bool": true, "arr": [1, null, "test"], "nested": { "blah": false, "blahblah": 3.14 }, "unicode": "\u2764" } "#;

// Parse from strings let parsed: JsonValue = s.parse().unwrap();

// Access to inner value represented with standard containers let object: &HashMap<_, _> = parsed.get().unwrap(); println!("Parsed HashMap: {:?}", object);

// Generate JSON string println!("{}", parsed.stringify().unwrap()); // Generate formatted JSON string with indent println!("{}", parsed.format().unwrap());

// Convert to inner value represented with standard containers let object: HashMap<_, _> = parsed.try_into().unwrap(); println!("Converted into HashMap: {:?}", object);

// Create JSON values from standard containers let mut m = HashMap::new(); m.insert("foo".to_string(), true.into()); let mut v = JsonValue::from(m);

// Access with Index and IndexMut operators quickly println!("{:?}", v["foo"]); v["foo"] = JsonValue::from("hello".to_string()); println!("{:?}", v["foo"]); ```

See the document to know all APIs.

Repository

https://github.com/rhysd/tinyjson

License

the MIT License