Skip to content

JSON to XML Converter

Paste JSON and get well-formed XML back — arrays become repeated sibling tags, keys prefixed with @ become attributes, and #text maps to element text content, matching the inverse of the site’s XML to JSON converter.

  • Configurable root element name (default root)
  • Arrays become repeated sibling tags automatically
  • Optional @attribute and #text convention (matches XML→JSON)
  • Pretty-print with configurable indent
  • Copy output and load a round-trip-friendly example
  • Runs fully client-side — nothing uploaded

Converter

Converted locally, nothing uploaded

How to convert JSON to XML

  1. 01

    Paste the JSON

    An object, array, or primitive — the converter wraps the value in your chosen root element.

  2. 02

    Set root name and options

    Change the root element name if you need something other than root, pick an indent size, and toggle the @attribute / #text convention when your JSON uses that mapping.

  3. 03

    Copy the XML

    Valid JSON updates the XML panel as you type. Use Copy when the output looks right; invalid JSON shows an error instead of partial XML.

Why JSON needs a root element when becoming XML#

JSON documents can be an object with several top-level keys, a bare array, or even a single string or number. XML documents, by contrast, must have exactly one root element that contains everything else. Without an explicit wrapper, { "a": 1, "b": 2 } has no single outer tag to hang both children on. This tool always wraps the parsed value in a configurable root (default root) so the result is a valid XML document no matter what shape the JSON had.

If your JSON already looks like the output of an XML→JSON conversion — for example { "catalog": { "book": [...] } } — set the root name to catalog and paste only the inner object, or keep the outer key as a child under root. Either way you stay in control of the element name that appears at the top of the file.

The @attribute and #text convention (and why it matters)#

XML distinguishes attributes from child elements; JSON does not. The widely used convention (xml2js, x2js, and this site’s XML to JSON tool) encodes attributes as keys prefixed with @ and puts mixed text content under #text. Turning that JSON back into XML without honouring those keys would either invent element names like @id (illegal in XML) or lose the attribute/element distinction forever.

With the convention enabled, { "book": { "@id": "1", "title": "X" } } becomes <book id="1"><title>X</title></book>. Disable it only when your JSON never uses those special keys and you want every key treated as a child element name — keys that are not valid XML names will then surface as clear errors instead of silent corruption.

How arrays become XML — and how to avoid the “last item wins” bug#

In JSON, a list is a first-class array. In XML, a list is just the same tag name repeated as siblings. This converter emits one element per array item using the property name that held the array: "book": [ {...}, {...} ] becomes two <book> siblings. That is the exact inverse of grouping repeated tags into arrays on the way from XML to JSON.

A top-level JSON array has no property name, so each entry is wrapped as <item> under your root. Nested arrays always reuse the key they were stored under. Numbers, booleans, and strings become text content; null becomes an empty self-closing tag. Special characters in text and attribute values are escaped (&, <, >, quotes) so the XML stays well-formed even when the JSON held markup-looking strings.

When to convert JSON to XML (and when not to)#

XML still shows up in SOAP APIs, enterprise feeds, sitemaps adjacent tooling, Android string resources, and legacy CMS imports. Converting a JSON payload you already have into XML for one of those consumers is a common glue step — especially when you need to inspect or hand-edit the result before shipping it.

If both ends of your pipeline speak JSON, stay on JSON. If you need schema validation against an XSD, generate or obtain XML that matches that schema rather than relying on a generic structural mapping. This tool is intentionally a faithful structural converter with a documented attribute/text convention — not a schema-aware mapper — so you can predict the output and round-trip with the companion XML to JSON converter on this site.

Frequently asked questions

Why do I have to choose a root element name?

XML requires a single root element. JSON can have multiple top-level keys or be an array. The converter wraps your value in the root name you provide (default root) so the output is always a valid XML document.

How are JSON arrays represented in the XML?

Each array item becomes a sibling element with the same tag name as the property that held the array. A top-level array is emitted as repeated <item> children under your root.

What do @id and #text mean in my JSON?

With the attribute convention enabled (default), keys starting with @ become XML attributes on the parent element, and #text becomes that element’s text content. This matches the mapping used by the XML to JSON converter on this site.

Can I round-trip with the XML to JSON tool?

Yes for typical documents that use the same @attribute / #text conventions. Comments, processing instructions, and DOCTYPE declarations are not present in JSON and will not reappear after a round-trip.

What happens if my JSON is invalid?

The tool shows a clear error message and hides the XML panel until the JSON parses successfully. Nothing partial is emitted.

Is my JSON uploaded to a server?

No. Conversion runs entirely in your browser — nothing is uploaded.

Developers

UUID Generator

Generate cryptographically random UUID v4 or time-ordered UUID v7, in bulk.

Developers

Base64 Encoder & Decoder

Encode and decode Base64 with correct UTF-8 handling, including the URL-safe alphabet.

Developers

ULID Generator

Generate ULIDs — sortable by creation time like UUID v7, but Crockford Base32 instead of hex.