| Crates.io | quick-xml-to-json |
| lib.rs | quick-xml-to-json |
| version | 0.1.0 |
| created_at | 2025-08-11 02:45:16.801331+00 |
| updated_at | 2025-08-11 02:45:16.801331+00 |
| description | High-performance conversion of XML to JSON |
| homepage | |
| repository | https://github.com/joshuaclayton/quick-xml-to-json |
| max_upload_size | |
| id | 1789492 |
| size | 42,193 |
High-performance XML to JSON converter built on top of quick-xml.
This crate provides a fast, memory-efficient way to convert XML documents to JSON format, leveraging quick-xml's high-performance XML parsing capabilities.
thiserrorAdd this to your Cargo.toml:
[dependencies]
quick-xml-to-json = "0.1.0"
use quick_xml_to_json::xml_to_json;
let xml = r#"<users count="3">
<user age="40">Jane Doe</user>
<user age="42">John Doe</user>
</users>"#;
let mut output = Vec::new();
xml_to_json(xml.as_bytes(), &mut output)?;
// output now contains the JSON bytes
let json_string = String::from_utf8(output)?;
println!("{}", json_string);
The crate converts XML to JSON using a specific format that preserves structure:
@ (e.g., @id="value")#t key#c key as an arrayExample XML:
<root id="main">
<child>Hello World</child>
<empty attr="value" />
</root>
Becomes:
{
"root": {
"@id": "main",
"#c": [
{
"child": {
"#t": "Hello World"
}
},
{
"empty": {
"@attr": "value"
}
}
]
}
}
This crate is designed for high-performance conversion of XML to JSON.
XML fixture files have been sourced from https://aiweb.cs.washington.edu/research/projects/xmltk/xmldata/www/repository.html.
On a 12-core MacBook Pro M4, throughput benchmarks vary but sit between 215 MiB/s and 340 MiB/s with minimal RAM usage (~3 MiB).
Run benchmarks with:
cargo bench
Run the test suite with:
cargo test
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a pull request.