jsonml

Crates.iojsonml
lib.rsjsonml
version0.4.2
sourcesrc
created_at2022-08-27 06:08:53.996995
updated_at2023-02-05 09:51:26.100782
descriptionJsonML deserialization and serialization
homepage
repositoryhttps://gitlab.com/gemmaro/rust-jsonml
max_upload_size
id653293
size40,195
(gemmaro)

documentation

README

JsonML crate

JsonML deserialization and serialization

Deserialization example:

# use std::collections::HashMap;
use jsonml::{Element, AttributeValue, Tag};

let element: Element =
    serde_json::from_str(r#"[ "li", { "style": "color:red" }, "First Item" ]"#)
        .expect("deserialize element tag");
assert_eq!(
    element,
    Element::Tag(Tag {
        name: "li".to_string(),
        attributes: HashMap::from([(
            "style".to_string(),
            AttributeValue::String("color:red".to_string())
        )]),
        element_list: vec![Element::String("First Item".to_string())]
    })
);

Serialization example:

# use std::collections::HashMap;
use jsonml::{Element, AttributeValue, Tag};

let element = Element::Tag(Tag {
    name: "li".to_string(),
    attributes: HashMap::from([(
        "style".to_string(),
        AttributeValue::String("color:red".to_string()))]
    ),
    element_list: vec![Element::String("First Item".to_string())]
});
assert_eq!(
    serde_json::to_string(&element).expect("serialize element tag"),
    r#"["li",{"style":"color:red"},"First Item"]"#
);

License

Licensed under either of the following at your option:

Commit count: 5

cargo fmt