quickxmltoserde

Convert XML to JSON using quick-xml and serde. Inspired by node2object.

Usage examples

Basic

Dependencies:

rust use std::fs::File; use std::io::prelude::*; use quickxml_to_serde::xml_string_to_json; Rust code to perform a conversion: ```rust // read an XML file into a string let mut xmlfile = File::open("test.xml")?; let mut xmlcontents = String::new(); xmlfile.readtostring(&mut xmlcontents)?;

// convert the XML string into JSON with default config params let json = xmlstringtojson(xmlcontents, &Config::newwithdefaults());

println!("{}", json); ```

Custom config

The following config example changes the default behavior to:

  1. Treat numbers starting with 0 as strings. E.g. 0001 will be "0001"
  2. Do not prefix JSON properties created from attributes
  3. Use text as the JSON property name for values of XML text nodes where the text is mixed with other nodes
  4. Exclude empty elements from the output

rust let conf = Config::new_with_custom_values(true, "", "text", NullValue::Ignore);

See embedded docs for Config struct for more details.

Conversion specifics

Additional info and examples

See mod tests inside lib.rs for more usage examples.

Edge cases

XML and JSON are not directly compatible for 1:1 conversion without additional hints to the converter. Feel free to post an issue if you come across one.