2 releases

0.1.1 May 26, 2022
0.1.0 May 26, 2022

#2086 in Parser implementations

MIT license

29KB
742 lines

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 = "*"

Dependencies

~1MB
~19K SLoC