How to convert JSON to XML
- Paste your JSON into Input (JSON), open a
.jsonfile, or click Sample. - Choose your Indent style (2 spaces, 4 spaces, tab, or minified), customize the Root and Item element names if needed, and toggle XML declaration.
- Click Convert to XML, then copy or download the well-formed
.xmldocument.
How JSON properties, arrays and attributes map to XML 1.0
The JSON document is wrapped in a single root element (<root> by default) and turned into well-formed XML 1.0.
- Attributes and text content: object keys starting with
@(for example"@id": "b1") become attributes on the enclosing XML element (id="b1"), and"#text"becomes the element's inner text. - Arrays: an array inside an object repeats that property's element for each item; a top-level or nested array wraps each entry in the configured item element (
<item>by default). - Empty and null values:
nullvalues and empty objects are emitted as concise self-closing tags (such as<field/>). - Safe tag names & escaping: keys containing spaces, leading digits, or symbols are sanitized into legal XML names, and special characters (
&,<,>,") are automatically escaped.
Example: JSON with attributes and arrays to XML
Input JSON:
{
"@version": "1.0",
"book": [
{ "@id": "b1", "title": "The Pragmatic Programmer", "price": 42.5 },
{ "@id": "b2", "title": "Clean Code & Design", "price": 38 }
]
}Converted XML output:
<?xml version="1.0" encoding="UTF-8"?>
<root version="1.0">
<book id="b1">
<title>The Pragmatic Programmer</title>
<price>42.5</price>
</book>
<book id="b2">
<title>Clean Code & Design</title>
<price>38</price>
</book>
</root>Frequently asked questions
- How do I create XML attributes and element text from JSON?
- Prefix any JSON property key with
@(for example"@id": "b1") to emit it as an attribute on the enclosing XML element (id="b1"). When an element has both attributes and text content, place the text under the"#text"key. - What happens if a JSON key contains spaces or starts with a number?
- XML 1.0 tag names cannot contain spaces or begin with a digit. The converter automatically sanitizes invalid characters into underscores and prepends an underscore to leading digits so the output is always well-formed XML.
- Can I convert the generated XML back into JSON?
- Yes. The XML to JSON Converter uses the same
@attributeand#textconventions, allowing clean round-trip conversions between JSON and XML.