JSON in XML umwandeln
JSON to XML converts a document in your browser. Members whose names start with the attribute prefix become XML attributes, an array repeats its member name rather than gaining a wrapper element, and a JSON key that is not a legal XML name is rewritten with the original preserved in a name attribute rather than silently mangled.
Die Oberfläche dieses Tools ist auf Englisch.
Die folgende Anleitung ist nur auf Englisch verfügbar.
How does JSON to XML work?
The hard direction is usually XML to JSON, because XML has more structure. Going the other way has fewer decisions but three of them are load-bearing, and getting any of them wrong produces output that is not well-formed XML at all.
JSON keys are not XML names
A JSON key can be anything: 2024 total, user.name, "", an emoji. An XML element name cannot start with a digit, cannot contain a space, and cannot be empty. The usual response is to substitute underscores, which silently destroys the key. Here the name is repaired the same way, and the original is written to a name attribute — so the document is well-formed and nothing is lost. The count of repaired keys is reported rather than buried.
An array root would produce two root elements
An XML document has exactly one root element; that is not a style rule, it is what makes a document a document. Writing the items of a top-level JSON array at the top level produces as many roots as there are items, and every XML parser rejects it. So an array root is wrapped, and its items take the item name.
An array that is a member is different: it repeats the member's own element name, because that is how XML expresses a list. There is no container element unless the JSON had one, which is what makes the output round-trip back through the XML to JSON converter with the same element in a force-array list.
Escaping is not optional
&, < and > in text, plus " and literal newlines in attribute values, all have to be escaped or the output is malformed. A newline inside an attribute is the one people miss: XML parsers normalise it to a space unless it is written as , so the value silently changes on the way back.
XML is bigger, and that is the trade
Every element name is written twice. The size difference is reported in the stats strip so the cost is visible. What it buys is attributes, namespaces, comments, processing instructions and schema validation — none of which JSON has, and any of which may be the reason you are converting.
JSON
{
"@id": "1",
"line": ["a", "b"],
"note": null
}XML
<?xml version="1.0" encoding="UTF-8"?> <root id="1"> <line>a</line> <line>b</line> <note/> </root>
What options and edge cases does JSON to XML support?
| Parameter | Type | Default | Behaviour & edge cases |
|---|---|---|---|
| Root name | element name | root | The single wrapping element. Required, because an XML document has exactly one root and JSON's top level does not supply a name. |
| Attribute prefix | string | @ | Members starting with this become attributes. Matches the XML to JSON converter's default, so a document survives a round trip through both. |
| Text key | string | #text | The member written as element content rather than a child element. This is how an element gets both attributes and text. |
| Item name | element name | item | Element name for the items of a top-level array, which has no member name to borrow. Arrays that are members repeat the member's name instead. |
| Indent | spaces | 2 | Zero emits one line, which is what you want on the wire — whitespace between elements is significant to a strict parser and pretty-printing changes the document. |
| Declaration | boolean | on | Emits <?xml version="1.0" encoding="UTF-8"?>. Turn it off when the output is a fragment being embedded in a larger document. |
| Self-close empty | boolean | on | null and empty objects become <a/> rather than <a></a>. The two are identical to every XML parser; some downstream tools are fussier than the spec. |
| Invalid key | repaired | original kept | A key that cannot be an element name is rewritten and the original written to a name attribute. The number repaired is reported above the output. |
| Escaping | automatic | — | & < > in text; & < > " and newlines in attribute values. An unescaped newline in an attribute is normalised to a space by the reader, which changes the value. |
Frequently asked questions
How do I get attributes instead of child elements?
Prefix the member name with @ — {"@id": "1"} becomes id="1" on the element. The prefix is configurable, and it is the same default the XML to JSON converter uses, so a document can go XML → JSON → XML and come back the same shape.
Why did my key get renamed?
Because it is not a legal XML element name: it started with a digit, contained a space or a character XML does not allow, or was empty. The element name is repaired and the original key is written to a name attribute, so nothing is lost and the document is well-formed. The count is shown above the output so you know it happened.
Why is there no wrapper element around my array?
Because XML expresses a list by repeating the element, not by wrapping it. {"line": ["a","b"]} becomes two <line> elements, which is idiomatic XML and what round-trips correctly. If you want <lines><line>…</line></lines>, put that nesting in the JSON: {"lines": {"line": ["a","b"]}}.
Should I indent the output?
Not for anything going over the wire. Whitespace between elements is significant in XML — a strict parser sees your indentation as text nodes, and for mixed content it genuinely changes the document. Indent for reading, set indent to zero for sending. This is a real difference from JSON, where whitespace never matters.
Can it produce a document that validates against my XSD?
Only by coincidence. A schema constrains element order, cardinality, datatypes and namespaces, and none of that information exists in JSON — an object's members have no meaningful order, so the converter cannot know what sequence your schema requires. Use this to get the shape, then reorder and add namespaces to match the schema.
Is my JSON uploaded?
No. The parse and the conversion run in the tab you already have open, which you can confirm in the Network panel. The usual reason to convert JSON to XML is to feed an older enterprise system, and the payloads involved are rarely ones you would want passing through an unknown server.