XML to JSON Converter
Paste XML and get structured JSON — attributes preserved under @_ keys, values left as strings, with a copy button and no upload.
- Free
- No account
- Runs in your browser
- Nothing uploaded
{
"catalog": {
"book": [
{
"title": "War and Peace",
"author": "Leo Tolstoy",
"price": {
"#text": "19.99",
"@_currency": "USD"
},
"@_id": "1"
},
{
"title": "The Idiot",
"author": "Fyodor Dostoevsky",
"price": {
"#text": "15.50",
"@_currency": "USD"
},
"@_id": "2"
}
]
}
}Runs entirely in your browser — your input is never uploaded, logged, or stored.Privacy policy
What is XML to JSON Converter?
XML and JSON are both text formats for structured data, and they are used for much the same work — configuration, API payloads, and data exchange — but they look very different. XML is verbose and tag-based (<book><title>War</title></book>), with attributes tucked inside the opening tag. JSON is the compact object-and-array format that JavaScript and most modern APIs read natively. When you take a legacy XML feed, an RSS or SOAP response, or a saved config file and need it as plain data, you have to turn the tree of tags into JSON objects.
This tool does that for you. You paste XML, and it maps the element tree to JSON: elements become objects, a text-only element becomes its string value, and repeated sibling elements become an array. Attributes are preserved too — kept under a distinct @_ key — so nothing in the source document is silently lost. The conversion is lossless: every element, attribute, and text node from the XML appears in the JSON. Nothing is uploaded; the whole conversion runs in your browser, so it is safe for private configuration or internal feeds.
Note that XML and JSON are not a perfect 1:1 match — XML allows attributes and mixed text-and-children that JSON has no native home for. The tool resolves that losslessly with a documented mapping rather than dropping data, which is why values are kept as strings and attributes live under @_ keys.
The tool first checks that the input is well-formed: every open tag has a matching close tag, there is a single root element, and self-closing tags are allowed. Comments, CDATA, and processing instructions are ignored because their contents are not tags. It then parses the element tree with a lossless mapping:
• An element with child elements becomes an object whose keys are the child names. • A text-only element becomes its string value. • Repeated sibling elements with the same name become an array. • Attributes are preserved under a distinct @_ key (for example <book id="1"> becomes @_id: "1"), so they never collide with a child element of the same name. • When an element mixes text and children, the text is kept under a #text key. • Values and attributes are kept as strings with no automatic number conversion, so something like a 5-digit code is never silently turned into a number.
This mapping is documented honestly because XML and JSON do not line up one-to-one: XML has attributes and mixed content that JSON has no native representation for. Instead of dropping them, the tool preserves them under the @_ and #text keys.
Worked examples
- <book><title>War</title></book> → { "book": { "title": "War" } }
- <book id="1"><title>War</title></book> → attributes appear under @_id
- <items><item>1</item><item>2</item></items> → repeated siblings become an array
How to use XML to JSON Converter
- Copy the XML you want to turn into JSON.
- Paste it into the input box.
- The tool converts it live and shows the JSON on the right.
- Click Copy JSON to copy the output, or copy it straight from the output box.
Common errors
- My input won't convert — the tool accepts well-formed XML only. Make sure every open tag has a matching close tag and there is exactly one root element; the error tells you it isn't valid XML rather than guessing.
- I don't see my attributes as normal keys — attributes are stored under a distinct @_ key so they never collide with a child element of the same name. Look for @_name keys in the output.
- A self-closing tag shows an empty string — an empty element like <b/> has no value, so it becomes an empty string. That is expected, not a bug.
FAQ
Where does my XML go?
Nowhere. The conversion happens entirely in your browser — the XML is parsed and re-rendered as JSON locally, and nothing is uploaded to a server.
Why are my attributes under an @_ key?
An attribute and a child element can share a name, so putting attributes in plain keys could overwrite real data. The tool stores attributes under a distinct @_name key to keep the conversion lossless — nothing is dropped.
Will the conversion lose any data?
No. The mapping is lossless — every element, attribute, and text node from the XML appears in the JSON. Attributes live under @_ keys and mixed text under #text, so nothing is silently discarded.
Why are numbers kept as strings?
XML has no concept of number types, so a value like a 5-digit code or a leading-zero number must not be silently turned into a number. The tool keeps every value as a string, and you can convert types in your own code.
Related tools
Prefer AllUtil on Google
One click adds AllUtil to your Google preferences. You'll see our tools highlighted with a Preferred badge in Search and AI answers.