JSON To Xml

Convert JSON to XML. Free JSON to XML converter.

Any JSON: an object, a list, a single value, or JSON Lines (one value per line). A key starting with @ becomes an attribute and #text the text inside its element, the way XML to JSON writes them.

Worth a look

Rate this tool

How useful was this tool?

JSON to XML Converter

Paste or type JSON into the box, load the Example, or Open a file up to 10 MB (you can also drag it onto the page). The XML appears as you type, ready to Copy or Download .xml. The download is named after the file you opened, so order.json becomes order.xml.

JSON and XML don’t map one-to-one, so the converter has to make decisions: how to write lists, what to call the root element, what to do with keys that aren’t valid XML names. Every decision is explained in a note under the result.

The conversion runs in your browser. Nothing you paste or open is uploaded.

Example

{
  "@id": "1001",
  "customer": "Maria Silva",
  "total": 24.50,
  "paid": true,
  "items": [
    { "sku": "TEA-01", "qty": 2 },
    { "sku": "MUG-07", "qty": 1 }
  ],
  "note": "Fragile & gift-wrapped"
}

With the root element named order, lists written as one element per item named item, 2-space indent and the XML declaration on:

<?xml version="1.0" encoding="UTF-8"?>
<order id="1001">
  <customer>Maria Silva</customer>
  <total>24.50</total>
  <paid>true</paid>
  <items>
    <item>
      <sku>TEA-01</sku>
      <qty>2</qty>
    </item>
    <item>
      <sku>MUG-07</sku>
      <qty>1</qty>
    </item>
  </items>
  <note>Fragile &amp; gift-wrapped</note>
</order>

What happened:

  • @id became an attribute of the root element instead of a child element.
  • The list became one <item> per entry inside <items>.
  • 24.50 was written exactly as typed. It isn’t shortened to 24.5.
  • The & was escaped as &amp;. A bare & would make the XML invalid.

The root element

An XML document must have exactly one element at the top. JSON doesn’t have that rule: it can be a list, or an object with several top-level keys. Under Root element, give the outer element a name that describes the data, like order, products or export.

Lists: two ways to write them

XML has no list type, so there are two common conventions, and the system you’re sending the XML to usually expects one of them.

Repeat the parent element for each item. Each entry gets the list’s own name:

<items>
  <sku>TEA-01</sku>
  <qty>2</qty>
</items>
<items>
  <sku>MUG-07</sku>
  <qty>1</qty>
</items>

This is compact and common in feeds and data exports. If you’d rather have the repeated elements named in the singular, rename the key in your JSON, for example from items to item.

One element per item inside the parent. The list keeps its own wrapping element, and each entry gets the name you enter under Element for list items, as in the example above. This is clearer, especially for lists of plain values such as tags, and closer to how many APIs and configuration files are laid out.

Attributes and element text

XML elements can carry attributes as well as content. JSON has no such distinction, so the converter follows a widely used convention:

  • Keys starting with @ become attributes. "@lang": "en" becomes lang="en".
  • A #text key becomes the element’s own text.
{ "title": { "@lang": "en", "#text": "Dune" } }

becomes:

<title lang="en">Dune</title>

XML to JSON uses the same convention, so a file can go from XML to JSON and back without losing its attributes.

Keys that aren’t valid XML names

JSON allows any text as a key. XML element names have rules:

  • They can’t start with a digit, a hyphen or a period.
  • They can’t contain spaces or most punctuation.
  • Names beginning with xml are reserved.

Keys like first name, 2024 or price (EUR) can’t become element names as they are. The converter changes them into valid names and lists every change in the notes, so you know exactly which names differ from your JSON.

Escaping and CDATA

Three characters need special handling in XML text: & becomes &amp;, < becomes &lt; and > becomes &gt;. In attributes, double quotes are escaped as well.

If your values contain a lot of HTML or code, the escaped text gets hard to read. Turn on Wrap text that holds <, > or & in CDATA and those values are wrapped in a CDATA section instead, which keeps them readable:

<description><![CDATA[<p>Loose-leaf <b>green</b> tea</p>]]></description>

A CDATA section can’t contain the sequence ]]>, because that’s what ends it. If a value includes it, the converter splits the section so the XML stays valid.

Values and types

XML has no number, boolean or null types; everything is text. The program reading the XML decides what each value means, often based on a schema. That’s why the converter writes values exactly as they appear in the JSON: 24.50 stays 24.50, true stays true, and long integers keep every digit, even beyond what JavaScript can store.

Formatting

  • Indent: 2 spaces, 4 spaces, a tab, or None (one line) for the smallest output.
  • XML declaration: the <?xml version="1.0" encoding="UTF-8"?> line at the top. Keep it for standalone files. Turn it off when the XML will be pasted into another document or sent to a system that adds its own.

When the JSON has a mistake

You get the line and column, an excerpt with the problem marked, and Show it in the text to jump to it. For the most common mistakes and how to fix them, see the JSON Validator.

JSON Lines (one JSON value per line) is accepted too.

FAQ

Why does everything look like text in the XML?

Because in XML it is. The system reading the file decides which values are numbers or dates, usually from its own schema or documentation.

Will the XML work with my system’s import?

The XML is always valid, but many systems expect specific element names, a specific order or namespaces, defined by their own schema. Check the system’s documentation or a sample file. You may need to rename keys in your JSON, or choose a different list style, to match.

Can I convert XML back to JSON?

Yes, with XML to JSON. One thing to know for round trips: when lists are written by repeating the parent element, a list with a single entry looks exactly like a single value. A converter reading it back can’t tell it was a list.

What other formats can I convert JSON to?

JSON to CSV, JSON to TSV and JSON to YAML.

Is my JSON uploaded anywhere?

No. Everything happens in your browser, and nothing you paste or open is stored.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us