wson

Crates.iowson
lib.rswson
version0.1.1
sourcesrc
created_at2022-05-26 15:29:07.585603
updated_at2022-05-26 15:40:09.977807
descriptionJSON parser made with nom
homepage
repositoryhttps://github.com/wat-aro/wson/
max_upload_size
id594167
size30,354
wat-aro (wat-aro)

documentation

https://docs.rs/wson/

README

wson

JSON parser made with nom.

Usage

let value = parse(
    "{\"menu\": {
       \"id\": \"file\",
       \"value\": \"File\",
       \"popup\": {
         \"menuitem\": [
           {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},
           {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},
           {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}
         ]
       }
    }}",
)?;
let expected = Value::Object(HashMap::from([(
    "menu".to_string(),
    Value::Object(HashMap::from([
        ("id".to_string(), Value::String("file".to_string())),
        ("value".to_string(), Value::String("File".to_string())),
        (
            "popup".to_string(),
            Value::Object(HashMap::from([(
                "menuitem".to_string(),
                Value::Array(vec![
                    Value::Object(HashMap::from([
                        ("value".to_string(), Value::String("New".to_string())),
                        (
                            "onclick".to_string(),
                            Value::String("CreateNewDoc()".to_string()),
                        ),
                    ])),
                    Value::Object(HashMap::from([
                        ("value".to_string(), Value::String("Open".to_string())),
                        (
                            "onclick".to_string(),
                            Value::String("OpenDoc()".to_string()),
                        ),
                    ])),
                    Value::Object(HashMap::from([
                        ("value".to_string(), Value::String("Close".to_string())),
                        (
                            "onclick".to_string(),
                            Value::String("CloseDoc()".to_string()),
                        ),
                    ])),
                ]),
            )])),
        ),
    ])),
)]));
assert_eq!(value, expected);

Installation

[dependencies]
wson = "*"
Commit count: 29

cargo fmt