JSON Converters Code Gen Formatters All tools Browse all tools built byAbhay Darji

XML to Rust Converter

Generate Rust types from XML instantly. Optional fields are detected automatically. Runs entirely in your browser.

100% client side No upload No size limit Works offline
Input
Output
Ready
Drop a file to load it

About this tool

Paste an XML sample and get Rust type definitions you can use immediately. Emits serde-derived structs. Fields are renamed to snake_case with `#[serde(rename)]` preserving the original key.

When you would use it

  • Deserialising with serde_json
  • Bootstrapping models from a real XML response instead of writing them by hand
  • Keeping types in step with an API that has changed

Worked example

XML
<?xml version="1.0" encoding="UTF-8"?>
<user id="4815">
  <name>Ada Lovelace</name>
  <active>true</active>
  <score>91.5</score>
  <roles>
    <role>admin</role>
    <role>editor</role>
  </roles>
</user>
Rust
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Root {
    pub user: User,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
    #[serde(rename = "@id")]
    pub id: i64,
    pub name: String,
    pub active: bool,
    pub score: f64,
    pub roles: Roles,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Roles {
    pub role: Vec<String>,
}

Things worth knowing

  • Every object in an array is merged when inferring the shape, so a field missing from one item is marked optional rather than assumed to always be present.
  • Identical nested shapes are de-duplicated into a single type instead of generating near-duplicates.
  • Array element types are named from the singular of the field name, so posts produces a Post type.
  • XML carries no type information, so numeric and boolean-looking text is inferred. Check the result where a value could legitimately be a string.
Questions

Frequently asked

How are optional fields detected?
By comparing every object in an array. A key present in some records but not others becomes optional; a key present in all of them is required. This is why passing several records gives better results than one.
Can it handle deeply nested XML?
Yes. Nested objects become separate named types, referenced from their parent, at any depth.
Is my data uploaded anywhere?
No. Every tool on JSONWorks runs entirely in your browser using JavaScript. Your input is never sent to a server, never logged and never stored. The simplest proof is to disconnect from the internet — the tools keep working. The site does load Google Fonts and a Google Analytics page-view tag, so you will see those two requests in your network tab, but neither receives anything you type or paste.
Related

Tools that pair well with this