Why JSON needs a root element when becoming XML#
JSON documents can be an object with several top-level keys, a bare array, or even a single string or number. XML documents, by contrast, must have exactly one root element that contains everything else. Without an explicit wrapper, { "a": 1, "b": 2 } has no single outer tag to hang both children on. This tool always wraps the parsed value in a configurable root (default root) so the result is a valid XML document no matter what shape the JSON had.
If your JSON already looks like the output of an XML→JSON conversion — for example { "catalog": { "book": [...] } } — set the root name to catalog and paste only the inner object, or keep the outer key as a child under root. Either way you stay in control of the element name that appears at the top of the file.
The @attribute and #text convention (and why it matters)#
XML distinguishes attributes from child elements; JSON does not. The widely used convention (xml2js, x2js, and this site’s XML to JSON tool) encodes attributes as keys prefixed with @ and puts mixed text content under #text. Turning that JSON back into XML without honouring those keys would either invent element names like @id (illegal in XML) or lose the attribute/element distinction forever.
With the convention enabled, { "book": { "@id": "1", "title": "X" } } becomes <book id="1"><title>X</title></book>. Disable it only when your JSON never uses those special keys and you want every key treated as a child element name — keys that are not valid XML names will then surface as clear errors instead of silent corruption.
How arrays become XML — and how to avoid the “last item wins” bug#
In JSON, a list is a first-class array. In XML, a list is just the same tag name repeated as siblings. This converter emits one element per array item using the property name that held the array: "book": [ {...}, {...} ] becomes two <book> siblings. That is the exact inverse of grouping repeated tags into arrays on the way from XML to JSON.
A top-level JSON array has no property name, so each entry is wrapped as <item> under your root. Nested arrays always reuse the key they were stored under. Numbers, booleans, and strings become text content; null becomes an empty self-closing tag. Special characters in text and attribute values are escaped (&, <, >, quotes) so the XML stays well-formed even when the JSON held markup-looking strings.
When to convert JSON to XML (and when not to)#
XML still shows up in SOAP APIs, enterprise feeds, sitemaps adjacent tooling, Android string resources, and legacy CMS imports. Converting a JSON payload you already have into XML for one of those consumers is a common glue step — especially when you need to inspect or hand-edit the result before shipping it.
If both ends of your pipeline speak JSON, stay on JSON. If you need schema validation against an XSD, generate or obtain XML that matches that schema rather than relying on a generic structural mapping. This tool is intentionally a faithful structural converter with a documented attribute/text convention — not a schema-aware mapper — so you can predict the output and round-trip with the companion XML to JSON converter on this site.