How the conversion works
JSON and XML describe data differently, so a converter has to make a few choices. This tool follows common conventions you can adjust with the options above.
- Objects become elements, and each key becomes a child element.
- Arrays become repeated elements with the same name, or a wrapper element with item children, as you choose.
- Attributes: a key that starts with @ becomes an XML attribute, and a key named #text becomes the text of the element.
- null becomes an empty element, and numbers and booleans become text.
- Special characters such as & and < are escaped for you.
Example
{"person":{"@id":"1","name":"Ann","skills":["js","php"]}}becomes
<person id="1">
<name>Ann</name>
<skills>js</skills>
<skills>php</skills>
</person>The root element
XML needs exactly one root element. If your JSON has a single top-level key, that key becomes the root. Otherwise the data is wrapped in the root name you enter, which is root by default.
Things to know
JSON keys that are not valid XML names, such as keys with spaces or a leading digit, are cleaned up by replacing bad characters with an underscore. XML also has no data types, so the number 5 and the text 5 look the same once converted.
Going the other way? Use the XML to JSON converter. To work from a file, see JSON to XML online. For control over indentation and formatting, use JSON to XML pretty print. Not sure which format to use? Read JSON vs XML.