Developer Tools

JSON to XML Conversion Explained (When and How)

Learn when JSON to XML conversion is still necessary, how elements and attributes map, how arrays become repeated elements, and which gotchas to avoid.

3 min read·Updated 2026-07-30

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

GotchaSymptomFix
Illegal element namesKeys with spaces or leading digits fail parsingNormalise to camelCase before converting
Unescaped charactersText with & or < breaks the documentLet the converter escape to &amp; and &lt;
Ambiguous nullsnull becomes an empty element or disappearsDecide: empty element, xsi:nil, or omit
Single-item arraysOne element is emitted without a wrapperForce array context so the repeat is stable
No root elementTop-level array has nowhere to liveName 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.

Tools used in this guide

Related guides