Home Tools Blog About

JSON to XML Converter

In short

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
Runs in your browser; the JSON you paste or open is not uploaded.
🛡
Private by designYour files and text stay in this tab
⚡
Runs in your browserNo waiting for a server
💧
No watermarksClean output you can use
🆓
FreeNo account needed

How to Use JSON to XML Converter

JSON to XML Converter · free online tool · All Tools Verse
The JSON to XML Converter tool, as it looks in your browser.
  1. Paste the JSON you want as XML, open a .json file, or click Sample.
  2. Set the root element name, how arrays are written (repeated elements or wrapped item elements) and what null becomes.
  3. Keep "Keys starting with @ become attributes" on if your JSON uses @id style keys, and the #text option for element text.
  4. Check the status line. It confirms that the browser could read the generated XML back, and the warnings list any renamed keys.
  5. 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 &amp; 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>
<name>Ada</name>
<age>36</age>
</user>
Array (default: repeat the element) {"tags": {"tag": ["red", "blue"]}} <tags>
<tag>red</tag>
<tag>blue</tag>
</tags>
Array (wrap in item elements) {"tags": ["red", "blue"]} <tags>
<item>red</item>
<item>blue</item>
</tags>
Attribute and text {"price": {"@currency": "EUR", "#text": 9.5}} <price currency="EUR">9.5</price>
null (default) {"user": {"phone": null}} <user>
<phone/>
</user>
null as xsi:nil {"user": {"phone": null}} <user xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<phone xsi:nil="true"/>
</user>
Key with a space {"user": {"first name": "Ada"}} <user>
<first_name>Ada</first_name>
</user>
Key starting with a digit {"scores": {"2024": 91}} <scores>
<_2024>91</_2024>
</scores>
Special characters {"note": "5 < 6 & \"7\""} <note>5 &lt; 6 &amp; "7"</note>
Special characters with CDATA {"note": "5 < 6 & 7"} <note><![CDATA[5 < 6 & 7]]></note>
Top-level array [1, 2] <root>
<item>1</item>
<item>2</item>
</root>
Several top-level keys {"a": 1, "b": 2} <root>
<a>1</a>
<b>2</b>
</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 as first name becomes first_name, and every rename is listed so nothing changes silently.
  • A prefix such as soap:Body is kept only when a matching @xmlns:soap key declares it, because a namespace prefix without a declaration makes the XML invalid.
  • Text is escaped (&amp;, &lt;, &gt;), 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.50 stays 1.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.

Keep going

Related Tools

All Document tools →
Share

Embed this tool

Add this free tool to your website. Copy and paste the code: