XML to JSON Converter
Convert XML to JSON in your browser: attributes become @name keys, mixed text becomes #text, and repeated elements become arrays — with errors that point at the exact line.
How to use this tool
Steps for using the XML Formatter.
- To JSON is selected. Paste XML into Input XML or click Upload file — the JSON appears as you type.
- Choose the JSON Indent (2 spaces, 4 spaces or tabs), and switch the output between Code and Tree to explore nested data.
- Attributes become
@namekeys, text next to attributes becomes#text, and repeated elements become arrays. - Errors in the XML point at the exact line and column. Copy or download the JSON when it looks right.
Example
Attributes, text and a repeated element
<?xml version="1.0" encoding="UTF-8"?>
<!-- order export -->
<order id="1042">
<customer>Ada Lovelace</customer>
<items>
<item sku="KB-1" qty="1">Keyboard</item>
<item sku="MS-2" qty="2">Mouse</item>
</items>
</order>{
"order": {
"customer": "Ada Lovelace",
"items": {
"item": [
{
"#text": "Keyboard",
"@sku": "KB-1",
"@qty": "1"
},
{
"#text": "Mouse",
"@sku": "MS-2",
"@qty": "2"
}
]
},
"@id": "1042"
}
}Common use cases
- Turning SOAP responses, RSS/Atom feeds or sitemaps into JSON for JavaScript code.
- Inspecting large XML documents in a collapsible JSON tree.
- Migrating XML configuration to JSON-based tools.
- Preparing XML data for APIs and databases that expect JSON.
How XML maps to JSON
XML and JSON don't line up one to one — XML has attributes, mixed text and repeated elements, JSON has objects, arrays and plain values — so every converter follows a convention. This one uses the widely used one: each element becomes a key, attributes become keys prefixed with @ (@id), and when an element has both attributes and text, the text goes under #text.
An element that appears more than once in the same parent becomes an array, as item does in the first example. An element that appears once becomes a single value — so if your data sometimes has one item and sometimes several, check for both shapes in the code that reads it.
XML has no number or boolean types, so every value stays a string: <port>8080</port> becomes "8080" and <debug>true</debug> becomes "true". Converting would guess wrong for values like ZIP codes or version numbers; cast them in your own code where you know the type. Empty elements become "".
The XML declaration and comments are dropped, since JSON can't hold them. The input is checked for well-formedness first, and errors point at the exact line. To go from JSON to other formats, see the JSON Formatter and JSON to YAML.
Limitations
- Every value is a string — numbers and booleans are not converted.
- A single element and a repeated one have different shapes (value vs array).
- Comments and the XML declaration are not kept; namespace prefixes stay part of the key names.
Frequently asked questions
How are XML attributes converted?
Each attribute becomes a key prefixed with @ — id="1042" becomes "@id": "1042". Text in an element that also has attributes goes under "#text".
Why is my number a string in the JSON?
XML has no number or boolean types, so the converter can't know whether 007 or 1.10 should be a number. Values stay strings; convert them in your code where you know the type.
Why is one element an array and another an object?
Repeated sibling elements become an array; a single element becomes one value. If a list can have one entry, handle both shapes when reading the JSON.
Is my XML uploaded?
No. Conversion runs entirely in your browser; files never leave your device.