Free Converter

JSON to XML Converter

Convert JSON to XML instantly. Supports custom root tags and indentation for clean, structured output.

Or

About JSON to XML Conversion

Converting JSON to XML is the inverse of the more common XML-to-JSON direction. The conversion is straightforward in spirit — turn each JSON object into an XML element, each key into a child tag, each value into the element's text — but XML imposes structural rules JSON does not have. Keys with special characters cannot become element names; arrays need a consistent representation; values that are objects need their own nested structure.

This converter uses a convention close to the one most XML-to-JSON tools follow: keys prefixed with @ become attributes on the parent element; a key named #text supplies the element's text content; arrays produce repeated elements with the same name. Following this convention keeps the round-trip consistent if you originally produced the JSON from XML.

Output XML is well-formed by construction: every element is properly closed, attribute values are quote-escaped, and text content is escaped for XML special characters (&, <, >). The result opens cleanly in any XML parser, validator, or tool that consumes XML.

Why Convert JSON to XML

Many established systems still expect XML even when their inputs come from modern JSON-producing pipelines. SOAP services, enterprise integrations, RSS publishers, government data submissions, and a long tail of legacy software accept XML and reject JSON. The conversion bridges modern producers to legacy consumers.

XML also supports features JSON does not have natively — namespaces, schemas (XSD), processing instructions, and a strong tradition of formal validation. For systems where these features matter (XML signatures, formally validated data exchange, complex schema constraints), generating XML output remains the right choice.

How to Convert JSON to XML

Paste JSON, get XML.

  1. Add your JSON: Paste JSON text into the input area or drop a file. The JSON must be valid; malformed input produces an error.
  2. Choose root element name: If your JSON has a single top-level object, its key becomes the root element automatically. For top-level arrays or primitives, specify a root name explicitly.
  3. Convert: The converter walks the JSON tree, mapping keys to element names, @-prefixed keys to attributes, and #text to text content. Arrays produce repeated sibling elements.
  4. Download or copy: Save as .xml or copy. Output is well-formed XML ready for any XML consumer.

Common Use Cases

Technical Details

The converter walks the JSON value recursively. Objects become elements; for each key in the object, an @ prefix means the key is converted to an attribute on the parent element, # text supplies the element's text content, and ordinary keys become child elements with the value recursed into the same conversion.

Arrays are converted to repeated sibling elements. An array under key items in JSON produces one <items> element per array item in the parent. This matches how XML-to-JSON converters represent multi-element collections.

Element names that would be invalid in XML (containing spaces, special characters, or starting with digits) are sanitized: spaces become underscores, invalid characters are stripped, and digit-leading names are prefixed. Attribute and text values are XML-escaped (& becomes &amp;, < becomes &lt;, etc.) to keep the output well-formed.

Best Practices

Frequently Asked Questions

How are JSON arrays represented in XML?
Each array element becomes a sibling XML element with the same name as the JSON key. For example, {"item": ["a", "b"]} becomes <item>a</item><item>b</item>.
How do I create XML attributes from JSON?
Use keys prefixed with @ in the JSON. {"book": {"@id": "1", "title": "X"}} becomes <book id="1"><title>X</title></book>.
What about JSON keys with special characters?
Element names containing spaces or special characters are sanitized: spaces become underscores, invalid characters are stripped. To preserve exact keys, the converter cannot — XML's element-name rules are stricter than JSON's key rules.
Are namespaces supported?
Namespaces require explicit attributes (xmlns or xmlns:prefix). Add them to the JSON as @xmlns and @xmlns:prefix keys to produce the corresponding XML.
Will the output be pretty-printed?
Yes by default — elements are indented for readability. Disable indentation if you need compact output for transmission.
Is my data uploaded to a server?
No. The conversion runs in your browser.
Can I round-trip JSON to XML and back?
Yes when both directions use the same conventions. JSON → XML → JSON typically reproduces the original; the inverse requires the JSON to be in the @attr/#text form before converting to XML.
What about JSON null values?
Null values become empty elements (<key/>). Some consumers may prefer omitting the element entirely; preprocess the JSON to drop null keys if needed.