JSON to XML Converter
Converts JSON to well-formed XML. Keys starting with @ become attributes, arrays become repeated elements or item lists, and keys that are not valid XML names are renamed and listed.
- Runs in your browser
- Nothing uploaded
- Free, no sign-up
How to Use JSON to XML Converter
- Paste the JSON you want as XML, open a .json file, or click Sample.
- Set the root element name, how arrays are written (repeated elements or wrapped item elements) and what null becomes.
- Keep "Keys starting with @ become attributes" on if your JSON uses @id style keys, and the #text option for element text.
- Check the status line. It confirms that the browser could read the generated XML back, and the warnings list any renamed keys.
- Copy the XML or download it as an .xml file.
Example: an order with attributes and a list of items
The Sample button loads this JSON. The keys @id and @currency are meant as attributes:
{
"order": {
"@id": "A-1042",
"@currency": "EUR",
"customer": {"name": "Ada Lovelace", "email": "[email protected]"},
"items": [
{"sku": "PEN-01", "qty": 2, "price": 3.5},
{"sku": "INK-07", "qty": 1, "price": 12}
],
"note": "Leave at door & ring twice",
"gift": false,
"coupon": null
}
}
The converter returns:
<?xml version="1.0" encoding="UTF-8"?>
<order id="A-1042" currency="EUR">
<customer>
<name>Ada Lovelace</name>
<email>[email protected]</email>
</customer>
<items>
<sku>PEN-01</sku>
<qty>2</qty>
<price>3.5</price>
</items>
<items>
<sku>INK-07</sku>
<qty>1</qty>
<price>12</price>
</items>
<note>Leave at door & ring twice</note>
<gift>false</gift>
<coupon/>
</order>
The status line reads Converted: 15 elements, 2 attributes. Checked: well-formed XML. Because order is the only top-level key, it became the root element. Each object in the items array became its own <items> element, the & in the note was escaped, and null became the empty element <coupon/>.
How JSON maps to XML
JSON and XML do not line up one to one, so every converter has to make choices. These are the ones this tool makes, each row produced by running it (declaration turned off to keep the rows short):
| Case | JSON | XML |
|---|---|---|
| Object | {"user": {"name": "Ada", "age": 36}} |
<user> |
| Array (default: repeat the element) | {"tags": {"tag": ["red", "blue"]}} |
<tags> |
| Array (wrap in item elements) | {"tags": ["red", "blue"]} |
<tags> |
| Attribute and text | {"price": {"@currency": "EUR", "#text": 9.5}} |
<price currency="EUR">9.5</price> |
| null (default) | {"user": {"phone": null}} |
<user> |
| null as xsi:nil | {"user": {"phone": null}} |
<user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| Key with a space | {"user": {"first name": "Ada"}} |
<user> |
| Key starting with a digit | {"scores": {"2024": 91}} |
<scores> |
| Special characters | {"note": "5 < 6 & \"7\""} |
<note>5 < 6 & "7"</note> |
| Special characters with CDATA | {"note": "5 < 6 & 7"} |
<note><![CDATA[5 < 6 & 7]]></note> |
| Top-level array | [1, 2] |
<root> |
| Several top-level keys | {"a": 1, "b": 2} |
<root> |
How it works
- The JSON is read with a strict parser that reports the line and column of any error. Fix common mistakes repairs comments, single quotes and trailing commas first.
- Element names must follow the XML rules: no spaces, no leading digit, and only letters, digits and
_ - .. A key such asfirst namebecomesfirst_name, and every rename is listed so nothing changes silently. - A prefix such as
soap:Bodyis kept only when a matching@xmlns:soapkey declares it, because a namespace prefix without a declaration makes the XML invalid. - Text is escaped (
&,<,>), and attribute values also escape quotes and line breaks. With the CDATA option, text that contains < or & goes into a CDATA section instead. - Characters that XML 1.0 forbids even when escaped, such as the control character U+0001, are removed with a warning.
- Numbers are copied exactly as written in the JSON, so
1.50stays1.50. - The result is parsed by the browser’s own XML parser before it is shown, and the status line says so when it reads back without errors.
Limits
- There is no schema. The tool cannot know that your target system wants a field as an attribute; mark those keys with @ in the JSON.
- With repeated elements, an empty array produces nothing, because there is no element to repeat. Choose “Wrap in an item element” if empty lists must show up.
- Key order follows the JSON unless you sort it. XML that needs a fixed element order from a schema may need keys reordered first.
- If two keys end up with the same name after renaming, only the first is kept for attributes, and you get a warning.
Frequently asked questions
How do I make an XML attribute from JSON?
Start the key with @. {“price”: {“@currency”: “EUR”, “#text”: 9.5}} becomes <price currency=”EUR”>9.5</price>. The #text key sets the text of the same element.
Why is my array inside a root element?
An XML document needs exactly one root element. When the JSON is an array, or has more than one top-level key, the tool wraps everything in the element named in Root element, which you can change.
Can the XML be converted back to the same JSON?
Mostly. The XML to JSON converter uses the same @ and #text conventions, and with “Turn numbers and true/false into JSON types” on, the Sample comes back the same except that null returns as an empty string.
What does xsi:nil mean?
It is the XML Schema way to say an element is null rather than empty. Pick it under “null values” if the system reading the XML checks for it; the tool then declares the xsi namespace on the root element.
Related Tools
XML to JSON Converter →
Converts XML to JSON with attributes, repeated elements, CDATA and namespaces handled. You choose…
Convert CSV to JSON →
Converts CSV or TSV to JSON in your browser. It detects the separator, handles…
Convert CSV to XML →
Convert CSV to XML with custom tag names, element/attribute modes, CDATA wrap, headerless mode.…
JSON to CSV Converter →
Turns a JSON array into CSV or TSV. Nested fields become their own columns,…
Convert JSON to PDF Report →
Convert JSON data to formatted PDF reports instantly. Free JSON to PDF converter with…
JSON to YAML Converter →
Turns JSON into clean, readable YAML. Strings that YAML would misread, such as NO,…
XML Formatter →
Formats XML with 2 spaces, 4 spaces or tabs, or minifies it to one…
Convert XML to PDF Invoice →
Convert XML invoice data to professional PDF invoices instantly. Support for UBL and custom…
XML to YAML Converter →
Convert XML into readable YAML that mirrors the document tree, with indentation for nesting.
YAML to JSON Converter →
Converts YAML to JSON with anchors, aliases and
Analyze JSON Online and Validate JSON Structure →
Analyze JSON Online Validate & Analyze JSON Structure with detailed statistics including depth, key…
Android AssetLinks JSON Generator - App Links →
Android AssetLinks JSON Generator files for Android App Links. Configure package names and SHA-256…