JSON to XML

Turn JSON into XML for SOAP services, legacy integrations and feeds, with a predictable mapping.

Tier 0 · browser · unlimited
112 characters
Output
<?xml version="1.0" encoding="UTF-8"?>
<order id="7">
  <item sku="A1">Mug</item>
  <item sku="B2">Poster</item>
  <total>20.5</total>
  <note/>
</order>

Mapping JSON to XML

Many older systems, payment gateways and government services still speak XML. This converter writes JSON as XML with a simple, reversible mapping:

  • each key becomes an element;
  • keys starting with @ become attributes of their parent;
  • a #text key becomes the element's text;
  • an array repeats the element once per item;
  • null becomes an empty element.

Characters with a meaning in XML (&, <, >, ") are escaped, and keys that are not valid element names (starting with a digit, containing spaces) are adjusted with underscores so the result is always well formed.

Worked example

{"order": {"@id": 7, "item": [{"@sku": "A1", "#text": "Mug"}, {"@sku": "B2", "#text": "Poster"}], "total": 20.5}}

becomes

<?xml version="1.0" encoding="UTF-8"?>
<order id="7">
  <item sku="A1">Mug</item>
  <item sku="B2">Poster</item>
  <total>20.5</total>
</order>

How this works

The page parses the JSON strictly and walks the value. If the root is an object with exactly one key, that key becomes the root element; otherwise the page wraps everything in the root element named in the options. Objects become elements, @ keys become attributes, #text becomes text content, arrays repeat their element, and scalars become text. Values are escaped for XML and invalid element names are fixed with underscores. Use XML to JSON for the reverse. Everything runs in this tab.

Frequently asked

How do I create attributes?

Prefix the key with @, as in {"@id": 7}.

Why was my key renamed?

XML element names cannot start with a digit or contain spaces, so 2nd item becomes _2nd_item.

What root element is used?

The single top-level key if there is one; otherwise the name in the Root element field.

Is my data uploaded?

No. Everything runs in your browser.

Sources

Reviewed Oct 17, 2026 · test vectors fixtures/dev/json-to-xml/