JSON to XML
Paste JSON. Get XML as you type. Nothing leaves your browser.
- 0
- Lines
- 0
- Keys
- 0
- Errors
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:
{
"book": {
"title": "JSON to XML Conversion",
"author": "John Doe",
"year": 2021
}
}<book>
<title>JSON to XML Conversion</title>
<author>John Doe</author>
<year>2021</year>
</book>Arrays become repeated elements
{
"user": {
"name": "John Doe",
"role": ["user", "admin"]
}
}<user>
<name>John Doe</name>
<role>user</role>
<role>admin</role>
</user>Attributes with $
Put attributes under $ and the text under _:
{
"product": {
"name": "Widget",
"price": { "$": { "currency": "USD" }, "_": "24.99" }
}
}<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
- The JSON WebsiteThe official website for JSON provides comprehensive information about the data format.
- ECMA-404The official ECMA standard that defines JSON.
- JSON on MDN Web DocsAn in-depth guide to JSON on the Mozilla Developer Network.
- JSON on WikipediaAn extensive article on JSON from the well-known online encyclopedia.
- W3Schools JSON TutorialA beginner-friendly tutorial on JSON from W3Schools.
- RFC 7159The IETF specification for JSON, defining it as a common format for data interchange on the web.
- RFC 8259The IETF specification that obsoletes RFC 7159, further defining the JSON data interchange format.
- JSON Tutorial on TutorialsPointA comprehensive tutorial that covers the basics of JSON.
- JSON Courses on CourseraA collection of courses on JSON offered by Coursera.
- JSON on StackOverflowQuestions tagged JSON give real-world problem solving scenarios.
- The History of JSONA playlist of videos that explain the history of JSON.
- The JSON Logo Design ProcessA playlist of videos that explain the history behind the JSON logo.
- JSON-LDA lightweight Linked Data format that lets you link JSON data to other JSON data anywhere.
- Swagger's Guide on JSON vs XMLA guide comparing JSON with XML for API design.
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.