DevSwitch.net
Back to Tools
⇄

JSON to XML Converter

Convert JSON data to XML format

File Converters

Tip: JSON can be an object or array. Nested structures are supported.

Runs in your browser

Input JSON

Convert JSON to XML in your browser

Paste JSON, open a .json file or drop it on the input window, and the XML appears as you type, indented and with an XML declaration on top. Keys become element names and nested objects become nested elements. Copy the result or download it as an .xml file.

Use it when a SOAP service, a feed or an older import only takes XML and your data comes from a JSON API. For the differences between the two formats, see XML vs JSON.

JSON to XML example

Real output for two user records. The array becomes rows, the address a nested element and each tag a repeated element:

users.json
[
  {"id": 101, "name": "Ivo Marsh", "address": {"city": "Lisbon", "zip": "1100-148"}, "tags": ["admin", "beta"]},
  {"id": 102, "name": "Lena Fisk", "address": {"city": "Oslo", "zip": "0150"}, "tags": ["beta"]}
]
users.xml
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <row>
    <id>101</id>
    <name>Ivo Marsh</name>
    <address>
      <city>Lisbon</city>
      <zip>1100-148</zip>
    </address>
    <tags>admin</tags>
    <tags>beta</tags>
  </row>
  <row>
    <id>102</id>
    <name>Lena Fisk</name>
    <address>
      <city>Oslo</city>
      <zip>0150</zip>
    </address>
    <tags>beta</tags>
  </row>
</root>

How JSON maps to XML

JSONXML
An array at the top A <root> element with one <row> per item
An object at the top A <root> element with one child per key
"tags": ["admin", "beta"] <tags> repeated, once per item
"@id": "u1" An attribute: id="u1" on the parent element
"#text": "Salt" The text of the parent element, next to its attributes
null, "" A self-closing tag such as <note/>
[] Nothing: an empty array writes no element
42, true Element text, <n>42</n>: XML has no number or boolean type

Tag names and escaping

JSON keys can be any string, XML names cannot. Keys and values are fixed so the document is always well-formed:

  • JSON

    "first name", "ns:id"

    XML

    Become <first_name> and <ns_id>. Characters other than letters, digits, _, - and . turn into underscores.

  • JSON

    "2024", "xmlns"

    XML

    Become <_2024> and <_xmlns>, because an XML name cannot start with a digit or with xml.

  • JSON

    "a & b <c>"

    XML

    Is written as a &amp; b &lt;c&gt;. Double quotes become &quot;, in text and in attributes.

Need the JSON back?

The XML to JSON converter reads attributes into @ keys and repeated elements into arrays, the same conventions used here.

JSON to XML questions

Start the key with @. {"book": {"@id": "b1", "#text": "Salt"}} becomes <book id="b1">Salt</book>, where #text sets the element's text.

Not in the tool: the outer element is always <root>, and array items are <row>. Rename them in the output if your schema needs other names.

Its value is an empty array. An array is written as one element per item, so with no items there is nothing to write. Use null if you need an empty tag.

Click Open file and pick the .json, or drop the file on the input window. Invalid JSON shows the parser's message in the output window; Download saves valid output as an .xml file.

No. Converting runs in your browser, and an opened file is read there too.