How to Convert JSON to XML

By Ramanathan Aug 11, 2026 1 min read JSON to XML Converter

Some systems — SOAP services, legacy APIs, certain config formats — still expect XML. Converting JSON to XML is straightforward once you know how the two structures line up.

How JSON maps to XML

Object keys become elements, and scalar values become the text inside them:

{ "note": { "to": "Dev", "body": "Convert me" } }
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <note>
    <to>Dev</to>
    <body>Convert me</body>
  </note>
</root>

Everything is wrapped in a single <root> element because XML documents must have exactly one root.

How arrays are handled

XML has no array type, so a JSON array is written as a repeated element — the same tag once per item:

{ "tags": ["fast", "free"] }
<tags>fast</tags>
<tags>free</tags>

A top-level array is a special case: since there's no key to name the elements, it's wrapped in <root> and each entry becomes an <item>.

Escaping and key names

Two things happen automatically to keep the XML well-formed:

  • Special characters (<, >, &) in values are escaped to &lt;, &gt;, and &amp;.
  • Invalid element names — keys with spaces or symbols, or starting with a digit — are sanitized (invalid characters become _), since XML element names have stricter rules than JSON keys.

The other direction

Need to go back? See How to Convert XML to JSON, and for choosing between formats, JSON vs XML vs YAML vs CSV.

Try it

Paste JSON and get clean, indented XML instantly — everything runs in your browser, nothing uploaded.

About the author

Ramanathan · Software Engineer & Solutions Architect

I'm a Software Engineer and Solutions Architect with 20+ years of experience building enterprise applications across BFSI, Healthcare, Retail, Manufacturing, and Industrial Automation. I've spent those two decades living in JSON, tokens, regexes, and config files — so I built the fast, private, no-login developer tools I always wanted to reach for myself.

Last updated: Aug 11, 2026