Converters
JSON to XML Converter
Turn any JSON document into well-formed XML — element per key, repeated tags for arrays, declaration included.
In short
Convert JSON to XML online: keys become elements, arrays become repeated tags, nulls become nil attributes. Free, instant, and 100% in your browser.
By NaveenKumar T · Updated
- Instant in-browser conversion
- Validates input first
- Well-formed XML with declaration
Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →
Example
JSON to XML: input and output
A weather-station reading with a nested location, an array of samples, a null field and a key containing a space — each one exercises a different mapping rule.
{
"station": "KSEA-07",
"location": { "lat": 47.45, "lon": -122.31 },
"readings": [
{ "time": "06:00", "temp_c": 12.4, "rain": true },
{ "time": "12:00", "temp_c": 18.9, "rain": false }
],
"alert": null,
"wind gust": 31
}<?xml version="1.0" encoding="UTF-8"?>
<root>
<station>KSEA-07</station>
<location>
<lat>47.45</lat>
<lon>-122.31</lon>
</location>
<readings>
<time>06:00</time>
<temp_c>12.4</temp_c>
<rain>true</rain>
</readings>
<readings>
<time>12:00</time>
<temp_c>18.9</temp_c>
<rain>false</rain>
</readings>
<alert nil="true"/>
<wind_gust>31</wind_gust>
</root>The two-entry readings array became two sibling <readings> elements rather than one wrapper, the null alert became a self-closing element with nil="true", and the key "wind gust" was renamed <wind_gust> to make a legal tag name. Everything sits under a generated <root> element.
Learn more
How JSON to XML conversion works
Every JSON object key becomes an XML element of the same name, with characters that are illegal in tag names replaced by underscores. Arrays become repeated elements — each item of "items" renders as its own <items> child — because XML expresses plurality by repetition rather than brackets. null values become self-closing elements marked nil="true", and string values are entity-escaped so <, &, and quotes can't break the document.
The output begins with a standard <?xml version="1.0" encoding="UTF-8"?> declaration and is indented two spaces per level, so it drops cleanly into config files, SOAP envelopes, or anywhere else XML is expected.
When to convert JSON to XML
JSON-to-XML conversion usually appears at integration boundaries: feeding REST API responses into legacy SOAP services, generating XML payloads for enterprise systems that predate JSON, producing sitemaps or RSS-like documents from JSON data, or satisfying a partner spec that simply demands XML. Converting mechanically — rather than hand-writing tags — eliminates the escaping mistakes that make XML consumers reject your payload. Check the result with the XML validator (well-formedness) and reindent it with the XML formatter before it goes into a SOAP body.
Help
Frequently asked questions
Everything you need to know about the JSON to XML.
01Why does my XML come out wrapped in a <root> element I did not ask for?
XML requires exactly one root element and a JSON object has none, so the converter wraps the whole document in <root>. Rename it with a find-and-replace, or nest your data under the key you want the root to be called before converting — {"order": {…}} produces <root><order>…</order></root>, and the inner element is the one most consumers want.
02How are JSON arrays represented in the XML output?
As repeated elements with the array's key name. {"items":[a,b]} becomes two consecutive <items> elements rather than one wrapper with children — the conventional XML idiom for lists. If your consumer expects a wrapper element, nest your array one level deeper before converting.
03What happens to null values, empty objects, booleans, and keys that aren't valid tag names?
null becomes a self-closing element flagged nil="true" (<phone nil="true"/>), an empty object becomes an empty element (<meta/>), and numbers and booleans are written as plain text — XML has no types, so true and "true" come out identical. Keys are sanitised into legal tag names: any character other than letters, digits, underscore, dot and hyphen becomes an underscore, and a key that starts with a digit gets a leading underscore ("2fa" becomes <_2fa>). The whole document is wrapped in a single <root> element.
04Does XML to JSON give me back the JSON I started with?
Almost, with two typed differences to expect. Repeated elements become an array only when they appear two or more times, so a one-item array round-trips as a single object; and every value is re-typed from its text, so "true" becomes true and "007" becomes 7. A null value written here as <alert nil="true"/> does not come back as null — it comes back as {"@nil": true}, since the parser has no special handling for XML's nil convention. Objects, nesting and key names otherwise survive exactly.
Keep working
Related tools
XML to JSON
Converters
XML Formatter
Re-indent any XML document into clean, readable markup — comments and CDATA preserved, validation built in.
XML Validator
Strict well-formedness checking with the exact line and column of every violation — fix XML errors in seconds.
JSON to YAML
Converters
JSON to CSV
Converters
JSON Formatter
Format, beautify, and validate JSON instantly in a professional VS Code-style editor — free, fast, and 100% private.