Skip to main content

json_to_xml

Function json_to_xml 

Source
pub fn json_to_xml(json: &str) -> Result<String, Box<dyn Error>>
Expand description

Converts a JSON value to XML.

Tabular JSON (array of objects) is wrapped in <root><item>.... Other JSON shapes are wrapped in <root> unless they are a single-key object, which becomes the root element directly. Keys starting with @ become attributes and #text becomes text content.

§Errors

Returns an error if the JSON is malformed.

§Examples

use sheeter_engine::json_to_xml;
let xml = json_to_xml(r#"[{"a":"1"}]"#).unwrap();
assert!(xml.contains("<root>"));