6 releases (3 breaking)
0.4.2 | Feb 5, 2023 |
---|---|
0.4.1 | Sep 21, 2022 |
0.3.0 | Aug 30, 2022 |
0.2.0 | Aug 29, 2022 |
0.1.0 | Aug 27, 2022 |
#1135 in Encoding
17KB
398 lines
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:
Dependencies
~0.5–1MB
~25K SLoC