Rust - Parser JSON to XML

I'm trying to perform the xml parser, however I didn't find any lib in rust to do it more or less in the same idea

https://goessner.net/download/prj/jsonxml/

If anyone knows and can help I would appreciate it.

There is GitHub - novcn/xml2json-rs: A rust library for converting to and from XML and JSON. which seems decent at a quick glance

There's also a few others on https://crates.io/search?q=json%20xml but many seem abandonded or incomplete

However, if you don't need a general tool but have some specific datasets in mind, there is a currently-active serde derive library for XML,
https://crates.io/crates/xml_serde
so you could define your data in normal serde-derive manner:

#[derive(serde::Serialize, serde::Deserialize)]
struct DataToConvert {
    name: String,
    items: Vec<SomeOtherThing>,
}
#[derive(serde::Serialize, serde::Deserialize)]
struct SomeOtherThing {
    and_so_on: String,
}

..then it should just be a case of using let d: DataToConvert = serde_json::from_string(...)?; then xml_serde::to_string(&d)

The advantage of this over a general xml2json type tool is you can do various data-validation and -modifications between the from_string and to_string - but that may be unimportant :person_shrugging:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.