JSON won the format war for web APIs, but XML has not gone away: enterprise SOAP services, document standards, build tooling and countless config files still require it. Knowing how to convert JSON into well-formed XML — and understanding what gets lost on the way — saves hours of hand-editing angle brackets. This guide covers the mapping rules and the traps.
When XML is still required
- SOAP and WS-* services — the payload must be XML, no negotiation possible.
- Document standards — DocBook, XHTML, SVG, Office Open XML and legal or government schemas are XML by definition.
- Configuration — Maven's pom.xml, Android manifests and many CI plugins expect XML elements.
- Feeds and publishing — RSS and Atom remain XML formats with strict consumers.
In those cases conversion is not a preference, it is a requirement — and the target schema usually dictates the exact structure, which the JSON to XML Converter can take as a guide.
Elements versus attributes
JSON has one way to attach a value; XML has two. The simplest mapping puts every key in an element:
<person><name>Ada</name><age>36</age></person>
Many schemas instead want metadata as attributes, commonly marked in JSON with an @ prefix:
{"person":{"@id":"7","name":"Ada"}} → <person id="7"><name>Ada</name></person>
Decide before converting: which keys are data (elements) and which are annotations (attributes)? A common convention also reserves #text for mixed content.
Arrays and repeated elements
JSON arrays have no name; XML elements do. Each item becomes a repeat of a child name, usually the singular of the key:
{"order":{"item":["pen","pad"]}} → <order><item>pen</item><item>pad</item></order>
If a schema expects a wrapping element such as <items>, supply it explicitly — converters cannot guess singulars like "child" for the key "children".
Common conversion gotchas
| Gotcha | Symptom | Fix |
|---|---|---|
| Illegal element names | Keys with spaces or leading digits fail parsing | Normalise to camelCase before converting |
| Unescaped characters | Text with & or < breaks the document | Let the converter escape to & and < |
| Ambiguous nulls | null becomes an empty element or disappears | Decide: empty element, xsi:nil, or omit |
| Single-item arrays | One element is emitted without a wrapper | Force array context so the repeat is stable |
| No root element | Top-level array has nowhere to live | Name a root such as <items> yourself |
Also remember that JSON object key order is preserved in practice but not guaranteed, while XML sibling order is meaningful for mixed content — check schemas that parse paragraphs of prose.
Validate the result
Once converted, run the output through the XML Formatter & Beautifier: it pretty-prints the document so structural mistakes are visible at a glance, and rejects malformed tags immediately rather than letting them fail downstream.
Frequently asked questions
Is JSON to XML conversion lossless? Only if your JSON already mirrors the target schema. Attribute conventions, ordering and namespaces usually need manual mapping rules first.
Should I convert back to JSON afterwards? Often yes — parse once at the boundary, then work internally with JSON. Round-tripping repeatedly risks drift.
What about YAML? YAML maps to JSON far more naturally than to XML; see YAML to JSON Converter for that path.