XML ↔ JSON Transformer
Convert XML to JSON and back, live, in both directions. Attributes, nesting and repeated tags all handled correctly.
XML
JSON
How XML ↔ JSON conversion works
XML elements, attributes and text don't map onto JSON in one obvious way, so this tool follows one explicit, consistent convention in both directions:
- An XML attribute becomes a JSON key prefixed with
@. - Text content that coexists with attributes or child elements becomes a
#textkey; an element with only text (no attributes, no children) collapses to a plain JSON string. - A single child element stays a plain object; as soon as a second sibling with the same tag name appears, both are collected into a JSON array — so repeated tags never silently overwrite each other.
// XML
<library>
<book id="1"><title>Dune</title></book>
<book id="2"><title>Foundation</title></book>
</library>
// JSON
{
"library": {
"book": [
{ "@id": "1", "title": "Dune" },
{ "@id": "2", "title": "Foundation" }
]
}
}
Conversion uses the browser's native DOMParser and XMLSerializer-equivalent string building — no external library, no server calls.
Frequently asked questions
How are XML attributes represented in the JSON output?
Each attribute becomes a JSON key prefixed with @, e.g. the id attribute on <book id="1"> becomes "@id": "1". Text content that coexists with attributes or child elements becomes a #text key.
What happens to repeated sibling elements, like several <book> tags?
They become a JSON array. A single <book> stays a plain object, but as soon as a second sibling with the same tag name appears, both are collected into an array so no data is silently overwritten.
Does it support CDATA sections?
Yes on import — CDATA content is read as plain text. Converting back to XML always emits escaped text rather than re-wrapping it in a CDATA block, since a JSON string can't record that it was originally CDATA.
Is it safe to paste sensitive XML or JSON here?
Yes. All parsing and conversion happens in your browser using the native DOMParser and JSON APIs; nothing is ever sent to a server.