JSON to XML Converter Online
This free converter turns JSON into XML and XML back into JSON, both directions in one tool. Going to XML it maps objects to nested elements, arrays to repeated elements, and primitives to text, wraps everything in a root element you can name, and pretty-prints the result with 2- or 4-space indentation. It is built for developers moving data between JSON APIs and XML systems such as SOAP services, RSS and Atom feeds, Android and SVG documents, and legacy configuration files.
Going the other way, it parses XML with the browser's own DOMParser, reports well-formedness errors clearly instead of crashing, places attributes under an @attributes key, keeps mixed text under #text, and collapses repeated sibling elements into JSON arrays. Because JSON and XML describe data with different models, a round-trip is approximate, but the conventions are predictable and documented below. Every conversion runs locally in your browser, so your data is never uploaded.
How to use JSON to XML Converter
- Choose a direction with the swap button — JSON to XML or XML to JSON. The output updates automatically as you type or paste, so there is no convert button to press.
- For JSON to XML, paste valid JSON, set the root element name, choose 2- or 4-space indentation, and toggle the XML declaration line on or off. Use an @attributes object (or @-prefixed keys) for attributes and a #text key for element text.
- For XML to JSON, paste well-formed XML. Attributes appear under @attributes, mixed text under #text, and repeated tags collapse into arrays. Malformed XML shows a clear error message instead of producing broken output.
- Copy the result with the copy button or download it as a .xml or .json file.
How JSON maps to XML
Each object key becomes an element, nested objects become nested elements, and arrays repeat the element once per item because XML has no native list type. Primitive values (strings, numbers, booleans) become text, and null becomes an empty, self-closing element. A key named @attributes (or any key starting with @) is emitted as XML attributes on the element, and a #text key supplies the element's text when it also has attributes or children. Keys that are not valid XML names — for example ones with spaces or a leading digit — are adjusted so the output stays well-formed.
{
"note": {
"@attributes": { "id": "1" },
"to": "Tove",
"tag": ["home", "urgent"]
}
}
becomes
<note id="1">
<to>Tove</to>
<tag>home</tag>
<tag>urgent</tag>
</note>How XML maps back to JSON
Every element becomes an object. Its attributes are grouped under an @attributes key, and repeated child elements that share a tag name are collapsed into a JSON array so a list of items becomes a real array. An element with only text and no attributes becomes a plain string; when text sits alongside attributes or child elements it is kept under #text. The document's single root element becomes the top-level key, which lets the result convert cleanly back to XML.
<book category="fiction">
<title>Dune</title>
<tag>sci-fi</tag>
<tag>classic</tag>
</book>
becomes
{
"book": {
"@attributes": { "category": "fiction" },
"title": "Dune",
"tag": ["sci-fi", "classic"]
}
}Conventions and limitations
- Values from XML stay strings — XML has no native number or boolean types, so "42" and "true" are kept as strings to avoid corrupting IDs, ZIP codes, and leading zeros.
- Round-trips are approximate: the JSON and XML data models differ, so whitespace-only formatting text, comments, processing instructions, and namespace prefixes are not fully preserved.
- Empty JSON arrays produce no elements (the repeated-element model cannot distinguish an empty list from an absent key), and null becomes an empty element.
- Attribute and element order follow the order of keys in the JSON, and invalid XML names are sanitized.
Related terminology
- Element
- An XML node written with tags, such as <title>Dune</title>. Objects and their keys become elements during conversion.
- Attribute
- A name="value" pair on an element's opening tag. Attributes are represented in JSON under an @attributes object.
- @attributes / #text
- The two reserved JSON keys this converter uses: @attributes holds an element's attributes and #text holds its text when the element also has attributes or children.
- Root element
- The single outermost element every XML document must have. You can name it when converting JSON that has no single top-level property.
- Well-formed XML
- XML that follows the syntax rules — properly closed and nested tags and one root element. The converter reports a parser error when the input is not well-formed.
Frequently asked questions
- How do I convert JSON to XML?
- Make sure the direction is JSON to XML, paste your JSON, and the XML appears instantly. Set the root element name and indentation, and choose whether to include the XML declaration line. Objects become elements, arrays repeat the element, and an @attributes object becomes attributes.
- How are JSON arrays represented in XML?
- XML has no array type, so each item in a JSON array is emitted as a repeated element sharing the same tag name. For example "tag": ["a", "b"] becomes <tag>a</tag><tag>b</tag>. Converting that XML back to JSON collapses the repeated tags into an array again.
- How are XML attributes and text handled when converting to JSON?
- Attributes are grouped under an @attributes key on the element's object. If an element has attributes or child elements as well as text, the text is stored under a #text key; an element with only text and no attributes becomes a plain string.
- Why isn't my XML to JSON to XML round-trip identical?
- JSON and XML use different data models, so the conversion is approximate. Formatting whitespace, comments, namespace prefixes, and the distinction between an attribute and a child element are not always preserved. The structure and values are kept, but the exact bytes may differ.
- Why are numbers and booleans quoted as strings in the JSON output?
- XML stores everything as text, so 42 and true arrive as the strings "42" and "true". The converter keeps them as strings rather than guessing types, which prevents IDs, phone numbers, and leading zeros from being silently changed.
- Is my data uploaded to a server?
- No. Both conversions run entirely in your browser using JavaScript and the built-in DOMParser, so your JSON and XML never leave your device.