Hunt
Skip to content

JSON to XML

Paste JSON to get formatted XML for SOAP services, feeds, config files and older APIs. Properties starting with @ become attributes, #text becomes an element's text, and arrays become repeated elements, the same conventions the XML to JSON converter uses, so data round-trips. Numbers are written exactly as in the JSON.

Runs in your browser

JSON

Paste JSON or press Sample

XML

XML will appear here

How JSON maps to XML

  • Each property becomes an element with the property's name.
  • Properties starting with the attribute prefix (@ by default) become attributes of the parent element.
  • The text key (#text) becomes the element's text, next to its attributes.
  • An array becomes the same element repeated: "roles": ["admin", "dev"] gives two <roles> elements.
  • XML needs exactly one root element. When the JSON has one top-level property, that is the root; otherwise everything is wrapped in a root element (<root> by default), and a top-level array becomes <item> elements.
  • <, > and & in text are escaped.

How to use the JSON to XML

  1. Paste JSON, or press Sample.
  2. Set the root element name, attribute prefix and text key if needed.
  3. Copy or download the XML.

Examples

Attributes, arrays and an exact number

Input
{"user":{"@id":"7","name":"Ada","roles":["admin","dev"],"balance":12345678901234567890.10}}
Output
<?xml version="1.0" encoding="UTF-8"?>
<user id="7">
<name>Ada</name>
<roles>admin</roles>
<roles>dev</roles>
<balance>12345678901234567890.10</balance>
</user>

The balance is copied as written; converting through JavaScript numbers would print 12345678901234567000.

A top-level array

Input
[{"name":"Ada"},{"name":"Grace"}]
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
<item>
<name>Ada</name>
</item>
<item>
<name>Grace</name>
</item>
</root>

Text with an attribute

Input
{"note":{"@lang":"en","#text":"Tea < coffee"}}
Output
<?xml version="1.0" encoding="UTF-8"?>
<note lang="en">Tea &lt; coffee</note>

Common errors and how to fix them

Property names that aren't XML names

JSON property names can be anything; XML names can't contain spaces or start with a digit. Rename the property, for example to first_name.

Invalid
{"first name":"Ada"}
Fixed
{"first_name":"Ada"}

The tool reports: "first name" can't be an XML element or attribute name: names start with a letter or _ and contain no spaces.

Options

Root element
The wrapper used when the JSON doesn't have exactly one top-level property (default root).
Attribute prefix and text key
Which properties become attributes (@ by default) and text (#text).
XML declaration
Start with <?xml version="1.0" encoding="UTF-8"?>.

Limitations

  • null and empty strings become empty elements; true and false become text.
  • Property names must be valid XML names.
  • No namespaces are added; write prefixed names (soap:Body) and xmlns attributes yourself.

Frequently asked questions

How do I make an attribute?

Start the property name with @: {"book": {"@id": "b1", "title": "XML"}} gives <book id="b1"><title>XML</title></book>.

Does it round-trip with XML to JSON?

Yes, both use the same conventions; converting XML to JSON and back gives the same XML, apart from comments and whitespace.

Why was my JSON wrapped in <root>?

XML documents have exactly one root element. When your JSON has several top-level properties or is an array, they're wrapped in the root element you choose.

Is my JSON uploaded?

No. The conversion runs in your browser, and nothing you paste is sent anywhere.