About JSON to XML
Although JSON is now mainstream, many enterprise systems — SOAP endpoints, banking APIs, legacy ERP, and some government platforms — still communicate in XML. This tool converts JSON to well-formed XML locally in your browser, handling nested objects, array-to-repeated-element mapping, and the XML entity escaping of <, >, &, and quotes. When the top level is an array or holds multiple keys, it wraps them in a single root element so the document stays strictly valid. Two constraints shape the output: XML has no array concept, so arrays become same-named repeated child elements, and JSON has no attribute concept, so fields become child elements by default (attribute mapping generally needs a convention prefix such as @ plus manual adjustment). For example, {"user":{"id":1}} becomes <user><id>1</id></user> with matching nesting. No data is uploaded, making it suitable for payloads with sensitive fields in SOAP requests, generated config files, and platform feeds. Misuse is mainly forcing JSON semantics across: JSON has no notion of metadata versus content, so generators make everything an element, and a consumer expecting attributes needs an agreed key-prefix convention that no tool can guess. The reverse direction has the opposite problem — XML permits repeated sibling elements while JSON does not, so an aggregation rule must be agreed before XML can round-trip back to JSON. When not to use it deserves stating too: if the consumer reads only JSON, conversion adds a pointless hop; if the target format supports comments and human editing such as YAML, XML is harder to maintain. And for large sets of homogeneous records the repetitive tags inflate the size noticeably. It fits integration with legacy systems that speak only XML, or cases that genuinely need namespaces and schema validation. Read the output back with a parser rather than only inspecting the text. Escaping and empty elements are where errors cluster: a value containing angle brackets or an ampersand must be escaped or parsing fails, and empty objects and arrays are represented differently, so reading back immediately exposes the look-right-but-fail-to-parse case. The extra pass costs little and keeps the problem upstream of production. A final premise is the encoding declaration: the output should state it explicitly, or a recipient parsing with a local default turns non-ASCII content into mojibake. The file must actually be written in that encoding, since a declaration that disagrees with reality is worse than none because the reader trusts it. Reading the file back with a parser verifies both at once. Compared with hand-writing mapping code, the value is seeing the structure before coding: one conversion shows whether the XML shape matches what the downstream expects, avoiding the case where the parser is written before the structure is known to be wrong. Use it to validate during integration and only then freeze the mapping into code, which costs far less than coding and debugging in the dark.
How It Works Internally
Conversion maps an object tree to an element tree: keys become element names and scalars become text nodes. The compromise is that attributes cannot be inferred — JSON carries no notion of metadata versus content — so generators either make everything an element or produce attributes only when a key naming convention says so. Duplicate sibling keys cannot occur in JSON, so repeated elements need no handling.
{"user":{"id":1,"name":"a"}}<user>
<id>1</id>
<name>a</name>
</user>Measured on This Page
| Fixed: collision dropped data | "my key" and "my_key" both sanitise to my_key, and the old code emitted two identically named elements — converting back to JSON let the second overwrite the first, silently losing a field. Suffixes now disambiguate: <my_key> and <my_key_2> |
|---|---|
| Fixed: leading digit | "1st" produced <1st>, and an XML name may not begin with a digit, so parsers reject the document. A leading underscore is now added: <_1st> |
| Array representation | Array items are wrapped in <item> (e.g. <i><item>1</item><item>2</item></i>), one of several common conventions alongside repeating the parent tag or adding a type attribute |
| Character escaping | & and < inside text become & and <, leaving the document parseable |
| Structure | Output carries an XML declaration and 2-space indentation under a default <root> |
XML carries one thing JSON cannot: order and repetition are expressed by sibling position, not by an array wrapper — which is why an empty array and a missing key can end up looking identical in the output, and why loading the file back may hand you a single node instead of a list. Naming is the other squeeze: spaces, leading digits and punctuation are illegal in a tag, so they are rewritten, and 2 distinct keys can collapse onto one name. Duplicate numbering and a digit prefix are applied here; a truly reversible encode would put the original key in an attribute.
How to Use
- Open "JSON to XML"
- Paste the JSON to convert
- Set the root element name
- Check that arrays expand into item nodes
- Click the copy icon to take the XML with declaration
Use Cases
- Integrate SOAP services — Convert JSON data into the XML body a SOAP endpoint expects.
- Generate config files — Produce XML for frameworks still using XML config (some Java/Android projects).
- Export data — Export JSON datasets as XML for systems that only support XML import.
- Debug messages — Quickly turn test JSON into XML to verify the other system's parsing.
- Learn formats — Compare JSON and XML to understand how each represents the same data.
- Generate XML feeds — Convert JSON product data into XML feed format for e-commerce platforms like Google Shopping.
- SOAP message prep — Transform JSON request bodies into SOAP XML envelopes for legacy web service integration.
FAQ
How do JSON arrays convert to XML?
XML has no array concept, so each array element is emitted as a repeated child element of the same name — the XML convention for lists.
Must XML have a single root?
Yes. The XML spec requires one root element. If your JSON top level is an array or multiple keys, the tool wraps a root node automatically.
Are special characters escaped?
Yes. < , > , & , and quotes become XML entities like < , > , & to keep output valid.
Does it support attributes?
JSON has no attribute concept, so all fields become child elements by default. Attribute mapping usually needs a convention prefix (e.g. @) and manual tweaks.
How are empty objects or arrays handled?
An empty array becomes an empty element wrap and an empty object a self-closing tag, avoiding illegal empty structures; parsers read them as empty containers.
Can I convert back to JSON?
Use our XML to JSON tool for the reverse direction.
The XML has a <root> and many <item> elements — why?
XML requires a single root while JSON top levels can be arrays or anonymous objects, so a <root> wrapper is added and array elements become <item>. Rename them for semantic clarity; the structure is unaffected.
What do @ and # mean for attributes and text?
They are the common convention: keys starting with @ become attributes and #text is the element text; converting back follows the same rules. If you prefer pure elements, disable attribute mapping in the options.