The core mapping: keys become elements
The conversion follows a simple rule — each JSON key becomes an XML element, and each primitive value becomes that element’s text content. An object nests as child elements; the structure of your JSON becomes the structure of your markup:
{ "user": { "name": "Jane", "id": 1042 } }
becomes
<user>
<name>Jane</name>
<id>1042</id>
</user>
The two genuinely awkward cases are arrays (XML has no array type, so a JSON array becomes repeated sibling elements under the same tag) and attributes (covered in the FAQ above). Understanding these two upfront explains 90% of “why does my XML look like that?” questions.
XML still matters — here’s where
It’s tempting to think JSON won everything, but XML remains the required format in entire ecosystems, and converting into it is a real need:
| Domain | Why XML |
|---|---|
| SOAP web services | Protocol mandates XML envelopes |
| RSS / Atom feeds | Feed specs are XML |
| Sitemaps | sitemap.xml is XML by spec |
| Office documents | .docx/.xlsx are zipped XML |
| Enterprise / legacy | Many B2B and government APIs |
| Android / Maven | Layouts and pom.xml configs |
If you’re integrating with any of these from a JSON-native codebase, JSON→XML is the bridge.
Special characters are escaped for you
XML reserves five characters — <, >, &, ", and ' — that can’t appear raw in text content without breaking the parser. The converter automatically escapes these into their entities (<, &, and so on), so a JSON string like "A & B <tag>" produces valid, well-formed XML rather than a parse error. You don’t need to pre-escape your JSON; just be aware that the output text will show the entity forms, which decode back to the original characters when parsed.
Keep the root single
XML requires exactly one root element, while JSON happily has multiple top-level keys or starts as an array. If your JSON isn’t already wrapped in a single parent object, wrap it before converting — otherwise the result isn’t well-formed XML. A quick { "root": [ ...your data... ] } envelope solves it.