JSON

JSON to XML Converter

Paste JSON to get well-formed XML. A single top-level key becomes the root element, each array item becomes a repeated element, and keys starting with @ become attributes, so XML converted to JSON here converts back to the same document.

Runs in your browser. Nothing you enter is sent to a server.

Not needed when the JSON has a single top-level key: that key is the root.
Indent
Converts as you type.
XML
<?xml version="1.0" encoding="UTF-8"?>
<order id="INV-1042">
  <customer>
    <name>Ana</name>
    <city>Jakarta</city>
  </customer>
  <item sku="KB-01">
    <name>Keyboard</name>
    <qty>1</qty>
    <price>450000</price>
  </item>
  <item sku="MS-07">
    <name>Mouse &amp; pad</name>
    <qty>2</qty>
    <price>125000</price>
  </item>
  <paid>true</paid>
</order>

Root element <order> (the only top-level key) · 13 elements

Advertisements

How JSON becomes XML

JSON has objects, arrays and a few value types; XML has elements, attributes and text. The converter maps them like this:

JSONXML
{"name": "Ana"}<name>Ana</name>
{"@id": "INV-1042"}an attribute: id="INV-1042"
{"#text": "450000"}the element's own text
{"tag": ["a", "b"]}<tag>a</tag><tag>b</tag>
[[1, 2]]<item><item>1</item><item>2</item></item>
1234567890123456789012345678901234567890, every digit kept
nullan empty element, <note/>

The characters &, < and > are escaped, so Mouse & pad is written as Mouse &amp; pad. Control characters that XML 1.0 cannot hold are left out and counted under the result.

Converting back

The rules match the XML to JSON Converter, so XML made here turns back into the same JSON. Two things do not survive the round trip, because XML cannot express them: null comes back as an empty string, and an array with one item comes back as a single value.

Click XML → JSON above to take the current result to the other page. The data travels after the # in the link and is never sent to the server.

Example

The order above has one top-level key, order, so it becomes the root element. Its @id becomes an attribute, and the two items in the item array become two <item> elements, each with a sku attribute.

Need the data in a spreadsheet instead? Use the JSON to CSV Converter.

Questions

How do I make an XML attribute from JSON?

Start the key with @. {"item": {"@sku": "KB-01", "name": "Keyboard"}} becomes <item sku="KB-01"><name>Keyboard</name></item>. A key named #text becomes the text of the element itself, so {"price": {"@currency": "IDR", "#text": 450000}} becomes <price currency="IDR">450000</price>.

How are JSON arrays converted?

Each item becomes its own element with the array's key as the name: {"tag": ["a", "b"]} becomes <tag>a</tag><tag>b</tag>. An array inside an array, or an array at the top level, uses <item> elements. An empty array writes nothing.

What is the root element?

XML needs exactly one root element. If the JSON is an object with one key, such as {"order": {...}}, that key is the root. Otherwise everything is wrapped in the name you type under Root element, "root" by default.

What happens to keys that are not valid XML names?

XML names cannot start with a digit or contain spaces and most symbols. Such keys are renamed, for example "1st name" becomes <_1st_name>, and every renamed key is listed under the result so nothing changes silently.

How are null, true and numbers written?

Numbers keep their exact digits, so long IDs are not rounded. true and false are written as text. null becomes an empty element such as <note/>, because XML has no null; converting back gives an empty string.

Is my data uploaded?

No. The conversion and the downloaded file are made in your browser. A share link carries the data after the # in the link, which browsers never send to a server.

Support this site

The tools are free and need no account. If one saved you time, a small donation helps keep them running.

Want a tool or feature? Suggest it for free, or donate and write your request in the message. Supporters' requests are looked at first.