JSON to XML Converter

Get well-formed, indented XML from JSON — with control over attributes and the root element.

runs in your browserno uploadno sign-up

Paste JSON or load the sample.

XML output

Output appears here as you type.

How JSON becomes XML

Each key becomes an element and each array becomes the same element repeated, so {"item":[1,2]} turns into <item>1</item><item>2</item>. Keys starting with the attribute prefix (@ by default) become attributes on their parent, and a "#text" key becomes the element’s text — the same conventions the XML to JSON converter uses, so the two round-trip.

XML needs exactly one root element. If your JSON has a single top-level key, that key is the root; otherwise everything is wrapped in a root element whose name you choose. Characters such as <, > and & are escaped, null becomes an empty element, and keys that are not legal XML names (starting with a digit, containing spaces) are adjusted with underscores.

Frequently asked questions

How do I create XML attributes from JSON?

Prefix the key with @: {"book":{"@id":"bk101","title":"Midnight Rain"}} becomes <book id="bk101"><title>Midnight Rain</title></book>.

What happens to a top-level array?

It is wrapped in the root element and each item becomes an <item> element.

Why was my key renamed?

XML element names cannot start with a digit or contain spaces and most punctuation. Such characters are replaced with _ and a leading underscore is added when needed, and the tool tells you when that happened.

Is there an XML declaration?

Yes, the output starts with <?xml version="1.0" encoding="UTF-8"?>.