JSON to XML

Convert JSON to XML.

FreeNo accountOn your device

Runs in your browser. How to verify

Loading tool…

About this tool

Paste a JSON object and get XML back inside a root element. Each key becomes a tag, arrays repeat the tag once per item, and characters such as & and < are escaped. There are no attributes: everything is element content.

How to use

1
Step 1
Paste a JSON object or array.
2
Step 2
Press Run.
3
Step 3
Copy the XML.

How it works

Keys become element names and scalar values become escaped text (& < > and double quotes). An array writes the same tag once per item. The output starts with an XML declaration and is wrapped in <root>. Null becomes a self-closing tag. A top-level array is written as repeated <item> elements.

Worked example

An object with an array

Input
{"user":{"id":1,"name":"Ada & Co","tags":["a","b"]}}
Output
<?xml version="1.0" encoding="UTF-8"?> <root><user><id>1</id><name>Ada &amp; Co</name><tags>a</tags><tags>b</tags></user></root>
Walkthrough
The ampersand becomes &amp; and the two array items become two <tags> elements. The result is one line, not indented.

Limitations

  • The root element is always called root.
  • Output is a single unindented line; run it through the XML formatter to read it.
  • Keys that are not valid XML names (for example ones starting with a digit or containing spaces) are written as they are and make invalid XML.
  • No attributes, namespaces or CDATA are produced.

Questions

How do I convert JSON to XML?
Paste the JSON and press Run. Keys become tags inside a <root> element.
How are JSON arrays represented in XML?
The array's tag is repeated once for every item.
Can I change the root element name?
Not in this tool; it always uses root. Rename it in the output.
Does it create XML attributes?
No. Everything becomes element content.

Features

  • Escapes & < > and quotes
  • Arrays as repeated tags
  • XML declaration included
  • Runs in your browser

Related resources

Guides and videos from around the web—opens on YouTube or the publisher’s site.

  • Learn JSON - Full Crash Course for Beginners

    freeCodeCamp.org

    Solid JSON syntax and nesting basics for formatter and validator tools.

    Watch on YouTube
  • Learn Regular Expressions - Crash Course

    freeCodeCamp.org

    Regex primer for tester and explainer pages.

    Watch on YouTube