JSON to XML Converter
Convert JSON data to well-formed XML documents with customizable root element and formatting options.
JSON to XML Converter tool
Example
Input: {"user":{"name":"Ada","age":36}} with Root Element Name: root
Result: <?xml version="1.0" encoding="UTF-8"?> / <root> / <user> / <name>Ada</name> / <age>36</age> / </user> / </root>
Each key becomes an element nested inside the root element, indented 2 spaces per level. Keys starting with @_ become attributes and special characters are escaped.
How JSON Becomes XML
| JSON input | XML inside the root element |
|---|---|
| {"name":"Ada"} | <name>Ada</name> |
| {"tags":["a","b"]} | <tags>a</tags><tags>b</tags> |
| {"user":{"@_id":"7","#text":"Ada"}} | <user id="7">Ada</user> |
| {"note":null} | <note/> |
| {"ok":true} | <ok>true</ok> |
| {"first name":"Ada"} | <first_name>Ada</first_name> |
| {"1st":"x"} | <_1st>x</_1st> |
| {"msg":"Tom & Jerry"} | <msg>Tom & Jerry</msg> |
| [1,2] (top level) | <item>1</item><item>2</item> |
Output of this converter, shown without indentation.
- Paste your JSON data into the JSON Input area.
- Set the root element name (defaults to "root").
- Choose the indent style - 2 spaces, 4 spaces, or tabs - and use @_ key prefixes for any values that should become attributes.
- View the generated well-formed XML output, with its XML declaration and proper element nesting, below the input.
- Click the copy button to copy the XML document for use in your SOAP API or enterprise integration.
Mapping JSON Data to XML Elements
This converter turns JSON into a well-formed XML document. Each key becomes an element, each value becomes the element's text, and everything sits inside a root element you can name. {"user":{"name":"Ada"}} becomes a user element holding a name element with the text Ada, with an XML declaration on top.
JSON and XML do not map one to one, so the tool follows simple rules. An array repeats its element once per item, so "tags": ["a","b"] gives two tags elements. A null value gives an empty element such as <note/>. Numbers and booleans are written as plain text, because XML has no data types of its own. A top-level array is wrapped in the root element, with each entry named item.
To make attributes, start a key with @_. To set text alongside them, use a #text key. So {"user":{"@_id":"7","#text":"Ada"}} becomes <user id="7">Ada</user>. These are the same conventions the XML to JSON Converter produces, so data can make a round trip.
XML names are stricter than JSON keys. Any character other than a letter, digit, _, ., : or - becomes an underscore, so first name becomes first_name, and a name that starts with a digit gets a leading underscore. The characters &, < and > are escaped in text and attributes, and double quotes are escaped inside attributes. You can indent with 2 spaces, 4 spaces or tabs. To reformat XML you already have, use the XML Formatter.
Sources
Frequently Asked Questions
Related Tools
XML to JSON Converter
Parse XML documents and convert to structured JSON, with attributes kept as @_-prefixed keys and well-formedness checks.
Developer ToolsJSON Formatter and Validator
Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.
Developer ToolsXML Formatter and Prettifier
Format, indent, and validate XML documents with customizable indentation and output options.
Developer ToolsJSON to YAML Converter
Convert JSON documents to YAML format with syntax validation, clean formatting, and instant preview.
Developer Tools