XML still runs a lot of the world: product feeds, RSS, bank and government data exports, SOAP APIs, sitemaps and older business software. But modern apps, JavaScript and most new APIs speak JSON. Converting XML to JSON is one of the most common data chores, and it has a few traps: attributes, repeated elements and numbers that should stay text.
This guide shows how XML maps to JSON, how to convert it for free in your browser, and how to fix the usual surprises.
The quick answer
- Open Doetra’s free data converter.
- Paste your XML or drop the file (up to 25 MB). The format is detected for you.
- Choose JSON as the output.
- Check the result, then copy or download it.
It’s free with no sign-up, and the conversion happens in your browser. Nothing is uploaded.
How XML maps to JSON
XML and JSON both describe nested data, but XML has a few extra features that JSON doesn’t. Here’s a small product feed:
<products>
<product id="0451" currency="BDT">
<name>Steel Water Bottle</name>
<price>450</price>
<tag>kitchen</tag>
<tag>eco</tag>
</product>
</products>A typical JSON version looks like this:
{
"products": {
"product": {
"@id": "0451",
"@currency": "BDT",
"name": "Steel Water Bottle",
"price": 450,
"tag": ["kitchen", "eco"]
}
}
}| XML feature | Typical JSON result |
|---|---|
Element <name>…</name> | A key: "name": "…" |
Attribute id="0451" | A key, often marked with a prefix like @ or _ |
Repeated elements (two <tag>s) | An array: ["kitchen", "eco"] |
| A single element | A plain value or object, not an array |
| Text that looks like a number | May become a number |
Namespaces (g:price) | Usually kept as part of the key name |
Different converters use slightly different conventions for attributes and text nodes, so always look at the output before you build code around it.
Step by step
- Open the converter, and paste your XML or drop the file. You can also open .xml files directly.
- If the XML has an error, such as a tag that isn’t closed, the converter points to the line, so you can fix it before converting.
- Pick JSON as the output and review it in code view.
- Copy it, download it, or share it as a link. The data lives inside the link itself.
The three traps, and how to handle them
1. One item vs many items
If a feed has two <product> elements, you get an array; if it has only one, many converters give a single object. Code that expects an array then breaks on small feeds. In your code, wrap single values: const list = Array.isArray(x) ? x : [x];
2. Codes that lose their zeros
SKUs, phone numbers and postcodes like 0451 can become the number 451. Check these fields in the output, and treat them as text in your code.
3. Attributes vs elements
The same value might be an attribute in one feed (id="0451") and an element in another (<id>0451</id>). Map both to the same field name in your app.
Common XML sources
- Google Shopping and marketplace product feeds: convert to JSON to load into a script or a store app.
- RSS feeds: turn blog or news feeds into JSON for a website widget.
- Sitemaps: list your site’s URLs as JSON, or as CSV to open in Excel.
- Bank, accounting and government exports: many still use XML.
- SOAP API responses: convert sample responses to JSON to understand the structure.
Going further
The same tool converts in every direction: XML, JSON, YAML, CSV, TSV and TOML, and it can generate TypeScript types, Zod schemas and JSON Schema. After converting XML to JSON, you can generate TypeScript types, describe it with JSON Schema, or turn it into a spreadsheet with our JSON to CSV guide.
Frequently asked questions
How do I convert XML to JSON for free?
Paste the XML into Doetra’s converter and choose JSON as the output. No sign-up, nothing uploaded.
What happens to XML attributes?
They become JSON keys, usually marked with a prefix so you can tell them apart from elements. Check the output for the exact names.
Can I convert a large XML file?
Yes, files up to 25 MB.
Can it convert JSON back to XML?
Yes. Paste JSON and choose XML as the output.
Try it: Convert XML to JSON free →