JSON & Data
How to Convert JSON to Well-Formed XML for SOAP, RSS and Legacy APIs
Turn JSON into well-formed, indented XML for SOAP, RSS and legacy APIs. See how objects, arrays and null map to elements, plus escaping and root tags.
Try the toolJSON to XML →XML has not gone anywhere
JSON dominates modern web APIs, but XML is still everywhere in the enterprise: SOAP web services, RSS and Atom feeds, sitemaps, Office documents, Android layouts and countless legacy integrations. Sooner or later you have data as JSON and a system that will only accept XML. Rewriting nested structures into angle brackets by hand is tedious and easy to get wrong — a single unescaped ampersand produces invalid XML.
How JSON maps to XML
JSON and XML do not line up perfectly — XML has attributes, namespaces and text nodes that JSON lacks — so a converter has to pick sensible conventions. The JSON to XML tool uses these rules:
- Each JSON object key becomes an XML element wrapping its value.
- A JSON array becomes repeated
<item>elements, because XML has no native list type. - null and empty values become self-closing tags like
<tag/>. - The characters
&,<and>in text are escaped automatically. - You choose the name of the single root element that wraps the whole document.
A worked example
With the root element set to library, this JSON:
{
"book": {
"title": "Clean Code",
"tags": ["craft", "quality"]
}
}becomes well-formed, indented XML:
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>Clean Code</title>
<tags>
<item>craft</item>
<item>quality</item>
</tags>
</book>
</library>Every level is indented two spaces and the XML declaration is prepended for you, so the output drops straight into a file or request body.
Pitfalls and things to expect
- Arrays become
<item>, not the key name. A JSON array undertagsrenders each element as<item>...</item>inside<tags>. If your target schema expects one<tag>per entry, rename after converting or restructure the JSON. - Everything becomes an element. JSON has no notion of XML attributes, so nothing is emitted as
attr="value"; the result is purely nested elements. A schema that requires attributes will need a manual tweak. - Invalid element names get sanitized. XML names cannot start with a digit or contain spaces, so a key like
"first name"or"123"is rewritten with underscores to keep the document well-formed. - Key order is preserved from the JSON object — but remember that not every JSON producer guarantees a stable key order.
Going the other way
When you receive XML and need JSON instead, the XML to JSON tool reverses the trip. And if you just want to tidy existing XML — fix indentation and spacing without changing structure — reach for the XML Formatter.
Conclusion
Generating XML from JSON by hand invites subtle well-formedness bugs; a deterministic converter handles escaping, indentation and the XML declaration so you can focus on whether the shape matches the target schema. Set your root element, paste the JSON, and copy the result — all locally in your browser, with nothing uploaded.