pub fn xml_to_json<R: Read, W: Write>(
reader: R,
out: W,
) -> Result<(), XmlToJsonError>Expand description
Convert XML to JSON
§Example Usage
use quick_xml_to_json::xml_to_json;
let xml = r#"<root><parent id="1"><child>Value</child></parent></root>"#;
let expected_json = serde_json::json!({
"root": {
"#c": [
{
"parent": {
"@id": "1",
"#c": [
{ "child": { "#t": "Value" } }
]
}
}
]
}
});
let mut output = Vec::new();
assert!(xml_to_json(xml.as_bytes(), &mut output).is_ok());
assert_eq!(
expected_json,
serde_json::from_slice::<serde_json::Value>(&output).unwrap()
);§Errors
This may error when:
- reading XML
- serializing strings to JSON
- converting a String to a byte array
- writing to the buffer