Crates.io | jsonml |
lib.rs | jsonml |
version | 0.4.2 |
source | src |
created_at | 2022-08-27 06:08:53.996995 |
updated_at | 2023-02-05 09:51:26.100782 |
description | JsonML deserialization and serialization |
homepage | |
repository | https://gitlab.com/gemmaro/rust-jsonml |
max_upload_size | |
id | 653293 |
size | 40,195 |
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"]"#
);
Licensed under either of the following at your option: