Skip to content

JSON to XML Converter

Convert JSON to XML as you type, with your own root element name and an optional XML declaration.

Input · JSON
⇄
Output · XML
Valid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to convert JSON to XML

  1. Paste JSON or open a file. The XML updates as you type.
  2. Set Root (default root), switch XML declaration on or off, and pick the Indent.
  3. Press ⇄ to check the round trip in XML to JSON.

Invalid JSON stops with the line and column of the mistake. JSON repair removes comments and trailing commas in one click; common JSON errors covers the rest.

Example

{
  "invoice": {
    "@number": "INV-77",
    "customer": "Kai Tanaka",
    "lines": [
      { "item": "Hosting", "amount": 20 },
      { "item": "Domain", "amount": 12 }
    ],
    "2fa enabled": true,
    "notes": null
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<invoice number="INV-77">
  <customer>Kai Tanaka</customer>
  <lines>
    <item>Hosting</item>
    <amount>20</amount>
  </lines>
  <lines>
    <item>Domain</item>
    <amount>12</amount>
  </lines>
  <_2fa_enabled>true</_2fa_enabled>
  <notes/>
</invoice>

The note under the output lists 2fa enabled as renamed.

How the mapping works

  • Root. An object with a single key, like invoice, uses that key as the root and ignores Root. Several top-level keys, a top-level array or a lone value are wrapped in the Root name; array items become <item> elements.
  • Attributes and text. @number became number="INV-77", and a #text key becomes the element’s text, matching what XML to JSON produces.
  • Arrays. Each item becomes an element named after the key, so <lines> appears twice. For a wrapper, nest it: {"lines": {"line": [...]}} gives one <lines> with two <line> children. An empty array becomes an empty element such as <tags/>, and an array inside an array is wrapped in <item> elements.
  • Empty values. null and {} become an empty element such as <notes/>.
  • Names. A name cannot start with a digit or contain spaces, so 2fa enabled became _2fa_enabled; symbols such as $ and / also become _.
  • Escaping. <, & and " in values are written as &lt;, &amp; and &quot;.

Questions

Is the XML declaration required?

No, XML 1.0 makes it optional for UTF-8 and UTF-16. Turn off XML declaration when the output goes inside another XML document, where a second declaration is an error.

Why did 49.0 become 49?

The JSON number is read as 49 before it is written out as text. If the exact digits matter, make it a JSON string.

Can it produce a SOAP envelope or another fixed format?

Yes, if you shape the JSON to match: prefixed keys such as soap:Body work, and an @xmlns:soap key becomes the namespace declaration.

Related tools

Esc