JSON to XML
Convert JSON to XML.
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
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 & Co</name><tags>a</tags><tags>b</tags></user></root>
- Walkthrough
- The ampersand becomes & 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?
How are JSON arrays represented in XML?
Can I change the root element name?
Does it create XML attributes?
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 YouTubeLearn Regular Expressions - Crash Course
freeCodeCamp.org
Regex primer for tester and explainer pages.
Watch on YouTube
- Working with JSON
MDN
Parse and stringify patterns that pair with browser-side JSON tools.
- Introduction to JSON Web Tokens
jwt.io
JWT structure for decoder and debugger pages.