Tutorial · 5 min read
How to Convert JSON to XML with Custom Root and Array Items
JSON to XML conversion sounds backward in 2026, but it's a real need. Legacy systems, SOAP APIs, enterprise integrations, and XML-based data feeds all expect XML. The catch: JSON's flexible structure doesn't map cleanly to XML's rigid hierarchy. You need a root element, arrays need naming, and primitive types need special handling. This guide covers it all with the JSON to XML Converter — zero dependencies, entirely browser-based.
The Core Challenge: JSON vs XML Structure
Consider this JSON. It's clean and compact:
{
"catalog": {
"book": [
{
"title": "XML for Beginners",
"author": "John Doe",
"price": 29.99
},
{
"title": "Advanced XML",
"author": "Jane Smith",
"price": 39.99
}
]
}
}
Converting this to valid XML requires decisions:
- What should the root element be if the JSON has no natural wrapper?
- How do array items get named?
<book>or<item>? - How are data types (numbers, booleans, nulls) represented?
The JSON to XML converter handles all of these with configurable options.
1. Setting the Root Element
XML requires a single root element for every valid document. If your JSON is an array or an object without a natural wrapper, you need to specify one:
<catalog>
<book>
<title>XML for Beginners</title>
<author>John Doe</author>
<price>29.99</price>
</book>
<book>
<title>Advanced XML</title>
<author>Jane Smith</author>
<price>39.99</price>
</book>
</catalog>
The Root Element input (default: root) controls this value. For most use cases, set it to a meaningful name like catalog, data, or response. The XML output updates instantly when you change this field.
2. Naming Array Items
JSON arrays become repeated XML elements. The tag name for each element is configurable via the Array Item input (default: item).
For an array like ["red", "green", "blue"]:
<root> <item>red</item> <item>green</item> <item>blue</item> </root> <root> <color>red</color> <color>green</color> <color>blue</color> </root>
Choose an Array Item name that makes semantic sense for your data. If the root is catalog, array items could be product. If the root is users, array items should be user.
3. Data Type Handling
JSON has distinct data types; XML elements are text. The converter preserves type information through the element structure:
| JSON Type | XML Output |
|---|---|
| String | <name>Alice</name> |
| Number | <price>29.99</price> |
| Boolean | <active>true</active> |
| Null | <middle_name xsi:nil="true"/> |
| Nested Object | Becomes child elements |
| Array | Repeated elements with Array Item name |
The XML output is always well-formed, with proper nesting and no orphaned elements.
Try the Free JSON to XML Converter
Paste JSON, configure root element and array items, see XML live. Zero dependencies, browser-native conversion.
Convert JSON to XML Now →Best Practices for JSON to XML Conversion
- Set a descriptive root element. Don't leave the default
root— use something domain-specific likecatalog,response, orconfig. - Name array items semantically. If the root is
users, items should beuser. If the root isproducts, items should beproduct. This makes the XML self-documenting. - Validate the XML output. After conversion, paste the result into an XML validator to ensure it's well-formed and matches your schema requirements.
- Handle arrays explicitly. If your JSON has deeply nested arrays, ensure the Array Item name doesn't collide with any existing element names in the same scope.
- Use JSON Editor for complex JSON first. If your JSON needs editing before conversion, use the JSON Editor to modify it, then paste the cleaned version into the converter.
Frequently Asked Questions
How do I convert JSON to XML online?
Paste your JSON into the JSON to XML Converter. Configure the root element name and array item name in the config bar. The XML output updates in real time. Download as .xml file when ready.
Why do I need a root element for JSON to XML?
XML requires a single root element for every valid document. JSON arrays and objects don't have this requirement. Adding a root element wraps the data in a top-level tag like <catalog> or <data> so the output is valid XML.
How are JSON arrays handled in XML?
Arrays become repeated XML elements with configurable names. The default array item name is item. For example, [1, 2, 3] with array item name number becomes <number>1</number><number>2</number><number>3</number>.
Can I edit the JSON before converting?
Yes. The JSON input panel is a full text editor. Make changes, and the XML output updates instantly. You can also beautify or minify the input using the toolbar buttons.
Is my JSON data safe with this converter?
100% safe. Conversion is done entirely in your browser. Your data never leaves your computer. Zero dependencies mean no third-party scripts are loaded. The tool works offline once the page is loaded.