EN

JSON to XML

Convert JSON to XML and back, preserving structure

FAQ

How is a JSON array represented in XML?

Each array element becomes its own repeated tag rather than an indexed container, the conventional way to express lists in XML.

Are XML attributes preserved?

Yes. They are kept in JSON with an @ prefix and restored on the way back.

Is CDATA handled specially?

No, its content is emitted as escaped text.

About this tool

JSON to XML always wraps the document in <root>, uses object keys as tag names, and emits one repeated tag per array element rather than an indexed container like <item index="0"> — the latter has no accepted convention in XML, while repeated tags are the standard way to express a list. Empty arrays, empty objects and null become self-closing tags <key/>, and text is escaped for & < > ".

The reverse direction follows three fixed rules: attributes become keys prefixed with @ (<book id="1"> → "@id": "1"), repeated sibling tags collapse into an array, and a node with attributes but no children keeps its text under #text. This is what makes an attribute → @key → XML round trip lossless.

Know the limits: XML text always becomes a string, with no type inference — <age>20</age> comes back as "20", not 20, because XML carries no types and guessing would corrupt values like 007, 1.0 or true. Mixed content (text plus child elements in one element) keeps only the children and drops the loose text; comments, processing instructions and the XML declaration are not carried over.

One commonly missed trap: a JSON key is not automatically a valid XML tag name. Keys containing spaces, starting with a digit or including characters like & produce invalid XML, and the tool will not rename them (renaming would falsify your data). Rewrite those keys to a valid form first, or use JSON ↔ YAML instead — YAML places no such restriction on key names.