/

JSON to XML

Processed Client Side

Convert a JSON structure into equivalent, properly indented XML markup with a configurable root element.

JSON · 9 lines
9 lines · 213 chars
Length: 213Lines: 9Size: 213 BytesCursor: 1:1
XML
XML
xmlLength: 297Lines: 12Size: 297 BytesCursor: 1:1

Bookmark this tool now — skip the search next time you need it.

About JSON to XML

This tool runs entirely in your browser. Whatever you paste is processed on your own device and is never uploaded, logged, or sent to any server.

The JSON to XML converter turns a JSON document into equivalent, properly indented XML markup — useful when a SOAP endpoint, a legacy integration, an RSS-style feed, or an enterprise system expects XML and everything upstream of it speaks JSON. Object keys become element names, nested objects become nested elements, and each item in an array repeats its parent element rather than inventing a wrapper. You control the indentation, whether the XML declaration is emitted, and the root element name used when the document has no single natural root. Keys that would be illegal as XML element names are sanitised automatically, and everything runs in your browser.

Key features

  • Objects, arrays, and primitives converted in one pass, with nesting preserved
  • Arrays repeat their element once per item — the shape most XML consumers expect
  • Automatic root handling: a document with one top-level key uses it as the root, anything else is wrapped in a root element you name
  • Optional <?xml version="1.0" encoding="UTF-8"?> declaration
  • Indentation as 2 spaces, 4 spaces, or tabs
  • Key names sanitised into valid XML element names — illegal characters become underscores, and a leading digit gets an underscore prefix
  • Ampersands and angle brackets escaped as &amp;, &lt;, and &gt; so the output is well-formed
  • Empty objects, empty arrays, and null values emitted as self-closing tags
  • Syntax highlighting on the JSON input and the XML output, with parse errors reported on the failing line

How to use it

  1. Paste your JSON into the input pane, or edit the sample that is already there.
  2. Set the indentation, type the root element name, and decide whether you want the XML declaration.
  3. Press Convert.
  4. Read the XML in the output pane and copy it.

Tips & common mistakes

  • The conversion is one-way by design. XML has attributes, namespaces, and mixed content that JSON has no equivalent for, so converting back will not reproduce your original document exactly.
  • Type information is lost: 42, "42", and true all become element text. A consumer that needs types has to get them from an XSD or from its own expectations rather than from the markup.
  • A single-item array and a plain value produce identical XML, because both emit one element. If the consumer must tell them apart, that distinction has to live in the schema.
  • Give the root a meaningful name when your JSON has several top-level keys. The default "root" is valid but says nothing, and many XML consumers key off the document element.
  • Keys with spaces, slashes, or colons are rewritten with underscores, since XML element names cannot contain them. Check the output if your keys are unusual — the sanitised name is what the consumer will see.
  • Turn the declaration off when the XML is being embedded inside a larger document; a declaration is only legal at the very start of a file.
  • Attributes are never generated — every value becomes element text. If the target system requires attributes, this output is a starting point to transform, not a finished document.
  • To inspect the generated XML with a collapsible tree before using it, open it in the XML Viewer & Formatter.

Related tools

Browse all 24 JSON tools

Frequently asked questions

10

Paste your JSON, choose the indentation and root element name, decide whether you want the XML declaration, and press Convert. The XML appears on the right, ready to copy.

Each item repeats the parent element rather than being wrapped in a container. An array of three books under "book" produces three <book> elements in sequence, which is what most XML consumers expect.

XML allows only one top-level element. If your JSON has a single top-level key, that key becomes the root; otherwise everything is wrapped in an element with the name you supply.

Not identically. XML has attributes, namespaces, and mixed content with no JSON equivalent, and type information is lost on the way out, so a round trip will not reproduce your original document.

They are sanitised — characters XML does not allow become underscores, and a name starting with a digit is prefixed with one. Check the output if your keys contain spaces, slashes, or colons.

null values, empty objects, and empty arrays are all emitted as self-closing tags such as <tag/>, which is the closest well-formed XML equivalent.

No. Every value becomes element text, so 42, "42", and true are indistinguishable in the markup. A consumer that needs types has to get them from an XSD or its own expectations.

No — every JSON value becomes an element with text content. If the target system requires attributes, treat this output as a starting point for a transform rather than a finished document.

No. The conversion runs entirely in your browser, so nothing is transmitted and the tool keeps working offline once the page has loaded.

SOAP services, older enterprise integrations, RSS and Atom feeds, some government and banking APIs, and plenty of internal systems still speak XML, even when everything built around them is JSON.