Skip to content
Aarrange

JSON to XML

Paste JSON. Get XML as you type. Nothing leaves your browser.

0
Lines
0
Keys
0
Errors
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result
The result shows here as you type.Try , or .
On this page

About JSON to XML Converter

Updated

JSON to XML Converter turns JSON (JavaScript Object Notation) into XML (Extensible Markup Language). Paste your JSON into the editor and the XML shows in the Result pane as you type. Press Convert to jump to the XML, then Copy or Download it.

The tool checks your JSON at the same time. When something is wrong, it rings the exact spot, gives the line and column, and says how to fix it. Format and Minify tidy the JSON itself.

Converting JSON to XML has its own challenges: XML needs one root element, every element needs a valid name, and data can be an attribute or an element. The converter handles each of these with clear rules, explained in the FAQ below.

Customization

Open Options to set the XML indent, the name of the root element, whether to start with an XML declaration, and whether text with < or & goes into CDATA sections. The tool remembers your choices.

Examples of JSON to XML conversions

A simple object becomes an element with child elements:

JSON
{
  "book": {
    "title": "JSON to XML Conversion",
    "author": "John Doe",
    "year": 2021
  }
}
XML
<book>
  <title>JSON to XML Conversion</title>
  <author>John Doe</author>
  <year>2021</year>
</book>

Arrays become repeated elements

JSON
{
  "user": {
    "name": "John Doe",
    "role": ["user", "admin"]
  }
}
XML
<user>
  <name>John Doe</name>
  <role>user</role>
  <role>admin</role>
</user>

Attributes with $

Put attributes under $ and the text under _:

JSON
{
  "product": {
    "name": "Widget",
    "price": { "$": { "currency": "USD" }, "_": "24.99" }
  }
}
XML
<product>
  <name>Widget</name>
  <price currency="USD">24.99</price>
</product>

Common uses

Configuration files

Some platforms, such as Maven, Spring and .NET, read their configuration as XML. Write the settings as JSON and convert them.

Sharing data between systems

When a system expects XML, for example an enterprise service bus, converting JSON to XML is the bridge between them.

SOAP web services

SOAP web services talk in XML. Converting a JSON request to XML lets a modern application call a SOAP service.

Other JSON resources

JSON to XML FAQ

Why convert JSON to XML?

You may need XML to work with older systems, SOAP web services, or industry standards that require XML. XML can also carry extra information in attributes and namespaces.

How are attributes and elements handled?

Every JSON key becomes an element by default. To make attributes, put them in an object under the key $, for example { "price": { "$": { "currency": "EUR" }, "_": "24.99" } }. The key _ holds the text of an element that also has attributes or children. This is the same shape the XML Formatter writes when it converts XML to JSON, so you can go back and forth.

What about arrays and nested objects?

Nested objects become nested elements. An array repeats its element once per item: "role": ["user", "admin"] becomes <role>user</role><role>admin</role>. A JSON document that is an array becomes <item> elements inside the root.

What happens to keys that are not valid XML names?

XML names cannot contain spaces and cannot start with a digit. The converter replaces characters that are not allowed with _, and puts _ in front of a name that starts with a digit. So 1st key becomes <_1st_key>.

What is the root element?

XML needs exactly one root element. When your JSON is an object with one key that holds an object, that key becomes the root. Otherwise the converter wraps everything in a root element, named root by default. You can change the name in Options.