Skip to content
SyntaxSnap

JSON to XML Converter

Paste JSON to get indented, well-formed XML. Name the root element, mark attributes with a key prefix, and get a note for any key that had to be renamed. One of our free JSON tools.

JSON

351 B

XML

How to convert JSON to XML

  1. Step 1

    Paste the JSON

    Paste it, drop a file, or load a URL with your browser.

  2. Step 2

    Name the root

    Set the root element and array item names and the attribute prefix.

  3. Step 3

    Copy the XML

    Copy it or download data.xml, with or without the XML declaration.

Worked example

@_id becomes an attribute, the tags array becomes two <tags> elements, and everything is wrapped in the root you chose.
Input: JSON
{"book":{"@_id":"bk101","title":"Dune","tags":["sci-fi","classic"],"price":9.99}}
Output: XML, root element catalog
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <title>Dune</title>
    <tags>sci-fi</tags>
    <tags>classic</tags>
    <price>9.99</price>
  </book>
</catalog>

How JSON maps to XML

JSON and XML model data differently, so a converter has to follow conventions. Here each object key becomes a child element with the same name, and its value becomes the element's content. Numbers and booleans are written as text, since XML has no types. An array becomes the same element repeated once per item: "tag": ["a", "b"] gives <tag>a</tag><tag>b</tag>. A JSON array at the top level, or an array directly inside another array, has no key to name its items, so the items use the Array item name, item by default.

null becomes an empty self-closing element such as <notes/>, and an empty string or empty array becomes an empty element with an opening and closing tag.

The root element

An XML document must have exactly one top-level element. The converter wraps your data in the element named in Root element. If you clear the name and your JSON is an object with a single key, such as {"rss": {...}}, that key becomes the root instead, so a document that came from XML converts back without an extra wrapper.

Attributes and text

Keys that start with the attribute prefix, @_ by default, become attributes of their parent element: "@_id": "bk101" becomes id="bk101". A #text key becomes the element's text content alongside its attributes. These are the same conventions that XML to JSON produces, so data survives a round trip. If your JSON uses a different prefix, such as @, change it in the toolbar.

Element names and escaping

XML names are stricter than JSON keys. They cannot contain spaces or most punctuation, cannot start with a digit, and names starting with xml are reserved. Keys like first name or 2fa are changed into valid names (first_name, _2fa) and a note above the output lists every change. Namespaced keys such as atom:link are kept as they are. In text and attribute values, &, < and > are escaped as entities, so the output is always well-formed.

Declaration and indentation

The output starts with <?xml version="1.0" encoding="UTF-8"?> unless you turn XML declaration off, which you may want when the XML will be embedded in another document. Elements are indented with two spaces.

Questions and answers

How do I make an XML attribute?

Start the key with the attribute prefix, which is @_ by default. {"book": {"@_id": "bk101", "title": "Dune"}} becomes <book id="bk101"><title>Dune</title></book>. Change the prefix in the toolbar if your data uses @ or something else.

How are arrays converted?

An array becomes the same element repeated once per item, so "tag": ["a", "b"] becomes <tag>a</tag><tag>b</tag>. A top-level array, or an array inside an array, uses the Array item name, item by default.

Why was one of my keys renamed?

XML element names cannot contain spaces or most punctuation, and cannot start with a digit or with "xml". Such keys are changed, for example "first name" to first_name, and a note lists every renamed key.

What is the root element?

XML needs exactly one top-level element. The converter wraps your data in the root element you name. Leave the name empty and, if your JSON is an object with a single key, that key becomes the root.

Are special characters escaped?

Yes. &, < and > in text are written as &amp;, &lt; and &gt;, so the output is always well-formed XML.

Related tools

All JSON & Schema tools

Next step

Need this built into your stack?

The team behind SyntaxSnap builds custom code generators, internal developer tools and API integrations.