JSON to XML
Convert a JSON object into XML elements and attributes.
Your result will appear here…
How to use JSON to XML
- Paste a JSON object.
- Select Convert.
- Review the XML and copy it.
Example
Input / settings:
{"person":{"name":"Ada","active":true}}Output:
<root>
<person>
<name>Ada</name>
<active>true</active>
</person>
</root>The tool adds the root element. Booleans and numbers are written as text.
When to use
- Prepare an XML payload example from a JSON sample.
- See how a JSON structure maps onto elements and attributes.
- Create test data for an XML-based integration.
Overview
JSON to XML wraps a JSON object in a root element named root and turns each property into a child element indented by two spaces. Arrays become repeated item elements, and the special keys @attributes and @text produce attributes and text content. The output has no XML declaration, and the top-level JSON value must be an object.
Supported input
JSON object
Output details
XML
Limitations
- The top-level JSON value must be an object. It is wrapped in a root element named root.
- Property names must be ASCII XML names. Other names are rejected, and a colon creates an undeclared namespace prefix.
Common mistakes
- Property names must be simple ASCII XML names. first name, 1a and 名前 are rejected, even though XML itself allows non-ASCII letters in names.
- A colon in a name creates a namespace prefix that is never declared. {"a:b":4} gives <a:b>, which XML Validator reports as an error in Chrome. Hyphens and dots are fine.
- null and an empty string both become an empty element, so they cannot be told apart. An empty array and an empty object both become a self-closing element.
- Arrays lose their property name for the items. "a":[1,2] is written as <a> containing two <item> elements, and nested arrays nest <item> elements.
- Numbers pass through JSON.parse first, so 12345678901234567890 is written as 12345678901234567000 and 1.50 as 1.5.
- The top-level value must be an object. An array, a string, a number or null is rejected.
Practical tips
- Put @attributes in the top-level object to add attributes to the root: {"@attributes":{"id":"1"},"x":1} produces <root id="1">.
- Validate the result with XML Validator before you send it on.
Privacy and security
This tool runs entirely in your browser. Your input is never uploaded to our servers. Conversion runs locally. Ampersands and angle brackets in text are escaped, and quotes inside attribute values are escaped too. Because property names must match a simple name pattern, a key cannot inject markup into the output.
References
- Extensible Markup Language (XML) 1.0: Names
- Namespaces in XML 1.0
- RFC 8259: The JSON Data Interchange Format
Frequently asked questions
Can I change the name of the root element?
No. The root element is always called root. A top-level property becomes a child of it.
How do I write XML attributes?
Use a property named @attributes whose value is an object. Each of its properties becomes an attribute of the surrounding element.
Does the output include an XML declaration?
No. The result starts with the root element and uses two-space indentation, with no options to change either.