Convert · JSON to XML

Convert JSON to XML

Turn JSON into clean, indented XML — every key becomes an element, arrays repeat their element. Runs in your browser.

No sign-up to start · Runs in your browser

JSON to XML
Open your JSON in the editor
JSON
XML

Runs entirely in your browser — nothing is uploaded.

{"order":{"id":"ord_9412","total":184.5,"items":[{"sku":"tee","qty":2},{"sku":"mug","qty":1}]}}
A JSON-to-XML converter maps JSON structure onto XML elements: each key becomes a tag, nested objects become nested elements, and array items repeat their element. JSON Copilot escapes the special characters &, <, and >, sanitizes keys into valid element names, and wraps the result in a single indented <root> element. Everything runs in your browser — nothing is uploaded and no account is required.

JSON to XML example

JSON input
{
  "book": {
    "title": "Tom & Jerry",
    "tags": ["kids", "classic"],
    "inStock": true
  }
}
XML output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <book>
    <title>Tom &amp; Jerry</title>
    <tags>kids</tags>
    <tags>classic</tags>
    <inStock>true</inStock>
  </book>
</root>

The tags array becomes two repeated <tags> elements, the ampersand in the title is escaped to &amp;, and the boolean is written verbatim as text — XML has no native types.

How to convert JSON to XML

  1. 1

    Paste your JSON

    Drop JSON into the input, or start from the loaded example. It can be a single object or an array of objects.

  2. 2

    Convert to XML

    Each key becomes an element, nested objects nest, and array items repeat their parent element. Scalar values are XML-escaped and written as text.

  3. 3

    Review the output

    The document is prefixed with an XML declaration, wrapped in one <root> element, and indented two spaces so it is well-formed and easy to scan.

  4. 4

    Copy the XML

    Copy the result to drop into a SOAP request, config file, or feed. Conversion happens locally, so nothing leaves your device.

  5. 5

    Open in the full editor

    Load your JSON in the editor to format, validate, and visualize it as a tree or mind map, and ask the AI copilot about its structure.

Why use this converter

Runs in your browser

Conversion is 100% client-side — your JSON never leaves your device and no account is needed.

Well-formed output

Every document gets an XML declaration, a single <root>, escaped text, and valid element names.

Arrays as repeated elements

Each array item is emitted under the same tag — the standard XML idiom for expressing a list.

Automatic escaping

The characters &, <, and > in text become &amp;, &lt;, and &gt; so the XML stays parseable.

Sanitized element names

Keys that are not valid XML names are rewritten: invalid characters become _, and a leading digit gets an underscore prefix.

Readable indentation

Two-space indentation and predictable nesting make the structure easy to read, diff, and review.

How JSON and XML model data differently

JSON and XML both describe hierarchical data, but their type systems are not the same. JSON has a small set of native types — strings, numbers, booleans, null, objects, and arrays — and a parser hands them back with those types intact. XML has exactly one primitive: text. Everything in an XML document is an element, an attribute, or a text node, and a bare parser sees "184.5" and "true" as strings until a schema or your own code says otherwise.

That gap drives every decision this converter makes. A JSON key maps cleanly to an element name, and a nested object maps to a nested element, because both are just named containers. Scalar values, however, have to collapse into text content: the number 184.5 and the boolean true are emitted exactly as they read, with no quotes and no type marker. If a downstream system needs to know that a field is numeric or boolean, it must apply an XML Schema or cast the values itself after parsing.

XML also carries features that have no JSON counterpart — attributes, namespaces, processing instructions, comments, and mixed content where text and elements interleave. A one-way JSON-to-XML mapping cannot invent meaning for those, so it produces a deliberately plain, element-only document that stays predictable and easy to reason about.

Why arrays become repeated elements — and why there are no attributes

JSON arrays have no direct equivalent in XML, so a convention is required. The widely used idiom is repeated sibling elements: a list becomes several elements that share one tag name. This converter follows that pattern by repeating the array parent’s key. An "items" array of two objects produces two <items> elements, and a "tags" array of two strings produces two <tags> elements. When the entire top-level value is an array, each item is wrapped in a generic <item> element so the document still has a single root.

The alternative — a wrapper element such as <items> that holds numbered children — is also valid, but repeated siblings keep the tag name tied to the data and read naturally in feed-shaped documents. The trade-off is that the array boundary is implicit: a consumer infers "list" from the repetition rather than from an explicit container.

The converter also never emits attributes; every value is an element. JSON gives no signal about which fields should be attributes versus child elements, and that choice is a genuine XML modeling decision with no canonical answer. An element-only document sidesteps the ambiguity, stays lossless, and round-trips predictably. It is more verbose than an attribute-heavy design, but it is far easier to generate, diff, and consume programmatically.

Escaping and valid element names

Text content is escaped so the output is always well-formed. The three characters that are significant in element text — &, <, and > — are replaced with &amp;, &lt;, and &gt;. A title like "Tom & Jerry" becomes "Tom &amp; Jerry". Quotes and apostrophes are left as-is, which is correct here: those only need escaping inside attribute values, and this converter never produces attributes.

Element names come straight from your JSON keys, but XML names are stricter than JSON keys. An XML name must begin with a letter or underscore and may then contain letters, digits, hyphens, periods, and underscores. The converter sanitizes each key to fit: any other character is replaced with an underscore, and a name that starts with a digit is prefixed with one. So "order-id" is kept, "user name" becomes "user_name", "@type" becomes "_type", and "2ndItem" becomes "_2ndItem". An empty key falls back to a single underscore.

A few structural rules round out the mapping. Empty objects, empty arrays, and null values render as self-closing tags such as <tag/> rather than empty pairs. The document opens with an <?xml version="1.0" encoding="UTF-8"?> declaration, wraps its contents in exactly one <root> element, and uses two-space indentation throughout, so the result is parseable by any standard XML tool.

Where JSON-to-XML conversion is useful

The most common reason to convert is interoperability with systems that speak XML. SOAP web services, older enterprise middleware, and many government or banking integrations expect XML request and response bodies. When a modern API hands you JSON and a legacy consumer needs XML, this converter gives you a clean, escaped payload to adapt into the target envelope. It is equally handy for populating XML configuration files or build descriptors from data you already model in JSON.

Feed- and document-shaped data maps especially well, because the repeated-element pattern mirrors formats like RSS, Atom, and sitemaps, where a channel or feed contains many same-named entries. A JSON array of records translates directly into the repeated <item>-style elements those formats expect, giving you a starting point you can drop into a template.

Once the JSON side is in good shape, open it in the full editor to go further. There you can format and validate it, explore deep structures as an interactive tree or a mind map, and ask the AI copilot to explain the schema or reshape the data before you convert. The converted XML is copy-ready on this page; the editor is where you refine the JSON that feeds it.

Frequently asked questions

Is the JSON to XML converter free and private?

Yes. It runs entirely in your browser with no account, and your JSON is never uploaded to a server.

How does it map JSON to XML?

Each key becomes an element and nested objects become nested elements. Array items repeat their parent tag, scalar values become escaped text, and the whole document is wrapped in a single <root> element.

Why does it not use XML attributes?

Every value is written as an element, never an attribute. JSON gives no signal about which fields ought to be attributes, so any attribute placement would be a guess. Keeping everything as elements makes the mapping unambiguous and easy to parse programmatically.

How are JSON arrays converted?

An array turns into repeated sibling elements that share the tag name of their parent key — for example ["a","b"] under a "tags" key becomes two <tags> elements. A top-level array wraps each item in an <item> element.

What happens to numbers, booleans, and null?

Numbers and booleans are written verbatim as text, such as 184.5 or true. null values and empty objects or arrays become self-closing tags like <tag/>. Because XML has no types, the consumer re-interprets these on parse.

What if my keys are not valid XML element names?

They are sanitized. Characters outside letters, digits, underscore, hyphen, and period are replaced with _, and a name that starts with a digit gets a leading underscore — so "2ndItem" becomes "_2ndItem" and "user name" becomes "user_name".

How is XML different from JSON?

JSON has typed scalars, objects, and arrays; XML is a text document of tagged nodes that also supports attributes, namespaces, and mixed content. Types collapse to plain text during conversion. To go the other way, use the XML to JSON tool.

Where does the converted XML go?

Copy the XML straight from the page, or open your JSON in the full editor to format, validate, visualize it as a tree or mind map, and use the AI copilot.

Related tools

Convert your JSON to XML

Open the Editor