Skip to content

JSON to XML Converter

Convert JSON data to well-formed XML documents with customizable root element and formatting options.

JSON to XML Converter tool

Loading...

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 inputXML 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 &amp; Jerry</msg>
[1,2] (top level)<item>1</item><item>2</item>

Output of this converter, shown without indentation.

  1. Paste your JSON data into the JSON Input area.
  2. Set the root element name (defaults to "root").
  3. Choose the indent style - 2 spaces, 4 spaces, or tabs - and use @_ key prefixes for any values that should become attributes.
  4. View the generated well-formed XML output, with its XML declaration and proper element nesting, below the input.
  5. 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

Each item becomes its own element named after the array's key. "item": [1, 2, 3] turns into three sibling item elements holding 1, 2 and 3. There is no wrapper element for the list itself. If your schema expects one, nest the array in an object, such as {"items": {"item": [1, 2, 3]}}.
Prefix the key with @_. {"book": {"@_isbn": "123", "title": "Dune"}} produces a book element with isbn="123" and a title child. To give an element both attributes and text, put the text in a #text key. Attribute values are escaped, so quotes and ampersands inside them are safe.
They are adjusted automatically. Spaces and characters such as $ or @ become underscores, and a name that begins with a digit or a hyphen gets an underscore in front. So "first name" becomes first_name and "1st" becomes _1st. The same rule applies to the root element name you type.
It will be well-formed, meaning any XML parser can read it. Whether it is valid against your XSD or DTD depends on element names, order and required fields, which the converter cannot know. Shape your JSON to match the schema, then check the output with a schema validator.
The tool always adds <?xml version="1.0" encoding="UTF-8"?> as the first line, since it is the standard way to start a document. If you are embedding the output inside another XML file, delete that first line after copying.

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 Tools

JSON Formatter and Validator

Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.

Developer Tools

XML Formatter and Prettifier

Format, indent, and validate XML documents with customizable indentation and output options.

Developer Tools

JSON to YAML Converter

Convert JSON documents to YAML format with syntax validation, clean formatting, and instant preview.

Developer Tools

JSON to TOML Converter

Convert JSON objects to TOML format with type preservation and clean table structure output.

Developer Tools

JSON to CSV Converter

Convert a JSON array of objects to CSV with automatic column headers, and convert CSV back to JSON in the same tool.

Developer Tools