Skip to main content
ToolsBay

JSON to XML

Convert JSON structures into equivalent XML markup.

Runs entirely in your browser — nothing is uploaded

JSON input

1 line

XML output

1 line

Frequently asked questions

How are JSON arrays represented in XML?

By repeating the element. XML has no array type, so ["a","b"] under the key "item" becomes two <item> elements. That is the standard convention and what XML parsers expect.

What happens to keys that are not valid XML element names?

They are sanitised. XML names cannot contain spaces or start with a digit, so "2 items" becomes "_2_items". Without that the output would not parse.

Is the output escaped safely?

Yes. The five XML-significant characters — & < > " and ' — are escaped in all text content, so a value like "Ada & Co" produces well-formed XML.

How is null represented?

As a self-closing element such as <note/>. XML has no null literal, so an empty element is the closest equivalent.

Converting a JSON tree to XML

JSON and XML both describe hierarchical data, but they do not map onto each other perfectly. JSON has arrays, numbers, booleans and null as distinct types. XML has elements, attributes and text, and everything is a string.

The conversion here takes the common, predictable approach: object keys become element names, array items repeat the element, scalars become text content, and null becomes an empty element. Nothing is turned into an attribute, because JSON gives no signal about which values were meant to be attributes.

Where you still need XML

SOAP web services, RSS and Atom feeds, sitemaps, office document formats and a great deal of enterprise and government integration all speak XML. If you are producing data for one of those and your source is JSON, this is the bridge.

Going the other direction, use XML to JSON. For an XML sitemap specifically, the sitemap generator produces the exact format search engines expect.

All developer tools