JSON ↔ XML Converter
Convert JSON to XML or XML to JSON using a clean key-to-element mapping. Browser-only, free.
About JSON ↔ XML Converter
JSON and XML model overlapping but distinct data shapes — JSON has clear distinctions between objects, arrays, and scalars, while XML has elements, attributes, and text. This converter uses a widely adopted convention: each JSON key becomes an XML element, arrays become repeated elements with the same name, keys prefixed with @ become attributes, and the special key #text holds element text content alongside attributes.
When to use it
- Bridging JSON-only APIs with legacy XML consumers (SOAP, RSS, OPML)
- Converting an XML response into JSON for use in a modern frontend
- Producing XML configuration from a JSON template
- Inspecting a complex XML document in a more navigable JSON form
How it works
JSON → XML walks the JSON value, emitting an element for each non-attribute key. Arrays produce repeated elements sharing the parent's tag. The @attr convention sets attributes; #text sets the element's text content. XML → JSON uses the browser's built-in DOMParser to read the document and groups same-named siblings into arrays.
Examples
{"book": {"@id": "1", "title": "Hamlet", "author": "Shakespeare"}}<book id="1"> <title>Hamlet</title> <author>Shakespeare</author> </book>
<library> <book><title>A</title></book> <book><title>B</title></book> </library>
{
"library": {
"book": [
{
"title": "A"
},
{
"title": "B"
}
]
}
}Frequently asked questions
- How are attributes represented?
- Attributes use a leading @ in the JSON. For example, <node id="1"/> becomes {"node": {"@id": "1"}} and round-trips losslessly.
- What about mixed content?
- An element that contains both attributes and text uses a #text key alongside the @-prefixed attributes. Mixed content with interleaved text and elements is approximated — XML's full mixed-content model has no clean JSON equivalent.
- Are XML namespaces preserved?
- Namespace prefixes appear in element names (ns:foo) but are not interpreted. The default namespace and xmlns declarations are treated as ordinary attributes.
- What XML versions are supported?
- Any XML the browser's DOMParser can read — that's XML 1.0 with the standard well-formedness rules. DTDs are not validated. CDATA sections are flattened into their text content.
- Why does JSON → XML need a single root?
- XML documents must have exactly one root element. If your JSON has multiple top-level keys, the converter emits the first one as the root and warns; wrap your JSON in a single outer object to be explicit.