JSON to XML Converter
Convert JSON to well-formed XML with indentation, custom root element, and attribute mode.
Acerca de esta herramienta
The JSON to XML Converter transforms any valid JSON document into properly indented, well-formed XML. Paste your JSON in the left panel and get instant XML output on the right. Customize the root element name to wrap the whole document, or leave it empty to auto-detect. Enable attribute mode to convert designated keys (those starting with @') to XML attributes rather than child elements. Array items are automatically wrapped in configurable item tags. The tool handles nested objects, arrays, nulls, booleans, and numbers correctly, escaping special characters such as <, >, and & in text nodes. Copy the result to the clipboard or download it as a .xml file. Useful for integrating with SOAP APIs, legacy enterprise systems, and any XML-based data pipeline that needs JSON input converted on the fly.
Cómo usar
- 1 Paste valid JSON into the input textarea on the left.
- 2 Optionally change the root element name (default: 'root').
- 3 Toggle attribute mode if your JSON uses @ prefix keys for attributes.
- 4 Set the array item tag name if you want something other than 'item'.
- 5 The XML output updates instantly. Click Copy to clipboard or Download XML.
Translating between two data shapes that don't quite match
JSON and XML both describe structured data, but they think about it differently. JSON has four primitive types (string, number, boolean, null) plus objects and arrays, and a value is simply a value. XML has only text and elements, no native notion of "number" or "array," but it adds attributes — metadata pinned to a tag rather than nested inside it. Converting one to the other is therefore not a lossless swap; it is a set of decisions about how each JSON construct should be expressed in tags. This tool makes those decisions explicit through its options, then builds the XML string entirely in your browser.
The rules this converter applies
Each JSON value maps to a tag named after its key. The mapping is consistent and worth knowing:
| JSON value | Becomes |
|---|---|
| A string, number, or boolean | A tag wrapping the text: <age>30</age> |
null | A self-closing tag flagged nil: <note xsi:nil="true"/> |
| An object | A parent tag containing one child tag per key |
| An array | A wrapper tag, with each element repeated under your chosen item tag |
| An empty object | A self-closing tag: <meta/> |
Because XML tag names cannot start with a digit or contain spaces, the converter sanitizes any key that would be illegal: invalid characters become underscores, and a leading digit gets an underscore prefix. That keeps the output well-formed even when your JSON keys were never meant to be element names.
A worked example
Feed it this JSON:
{ "user": { "name": "Alice", "tags": ["admin", "editor"] } }
With the root element set to root and the array item tag set to item, you get:
<root><user><name>Alice</name><tags><item>admin</item><item>editor</item></tags></user></root>
Notice the array did not invent element names from its contents — it can't, because array elements have no keys. Instead each entry is wrapped in the repeatable <item> tag. Rename that to tag and the editor tags become <tag>admin</tag>, which often reads more naturally.
Attribute mode: the @ convention
Real XML leans heavily on attributes — <user id="42"> is far more idiomatic than burying the id in a child element. Plain JSON has no way to mark "this key is an attribute," so this tool adopts a common convention: turn on Attribute mode, and any key whose name starts with @ is emitted as an attribute on its parent instead of a nested tag. So { "@version": "1.0", "name": "Alice" } produces <root version="1.0"><name>Alice</name></root>. This is the single most useful option for producing XML that downstream parsers expect.
Practical tips
- Pick indentation to match your target. Two spaces is compact and diff-friendly; tabs suit codebases that standardize on them. The indent setting only affects whitespace, never the data.
- Keep the XML declaration on for files, off for snippets. The
<?xml version="1.0" encoding="UTF-8"?>header belongs at the top of a standalone document but is noise if you are pasting a fragment into a larger file. - Name the root for the consuming system. Many APIs require a specific document root (
<Envelope>,<feed>). Set it here rather than editing the output afterward. - Let special characters be escaped for you. The converter automatically turns
&,<,>, quotes, and apostrophes into their XML entities, so a value likeTom & Jerrywon't break the document.
Common mistakes
- Expecting arrays to become numbered tags. XML has no array type, so a list always becomes repeated identical tags. If you need indices, add them to your JSON as attributes before converting.
- Hyphenated or space-containing keys.
"first name"is valid JSON but not a valid tag, so it is sanitized tofirst_name. Rename keys upstream if the exact tag name matters. - Forgetting attribute mode is opt-in. A key like
@idstays a literal<@id>-style child (sanitized) until you enable attribute mode. - Pasting invalid JSON. The tool parses with the browser's strict JSON parser, so trailing commas or single quotes will be rejected with an error message rather than silently mangled.
JSON to XML versus the reverse trip
It's worth remembering that this conversion is one-directional and not perfectly reversible. Going from JSON to XML throws away type information — the number 30 and the string "30" both become the text 30 inside a tag, and the boolean true becomes the word true. If you later parse that XML back to JSON, a generic parser has no way to know whether those were numbers, booleans, or strings; everything comes back as text unless you re-apply a schema. So treat the XML as a presentation or interchange format for a consuming system, not as a lossless archive of your original typed data. When you need round-trip fidelity, keep the JSON as the source of truth.
Where your data goes
Nowhere. Parsing and conversion happen locally in JavaScript; the JSON you paste is never uploaded, and the Download button simply saves the generated text from memory. The tool works offline, which is the simplest proof that nothing is transmitted.
Preguntas frecuentes
Formatea, valida y minifica JSON — con señalización exacta de errores de sintaxis.
Format, validate, and minify XML with syntax highlighting.
Convert JSON to CSV and CSV to JSON with nested object flattening and smart type detection.