Skip to content
Buy me a coffee
Converters

JSON to XML Converter

Convert a JSON file into XML. A default root element is created, JSON array entries become individual XML elements and all property values become text nodes.

0 characters · 0 lines
Option 2: Or upload your JSON file
Element created for each entry of a JSON array.
Ctrl + Enter

JSON to XML conversion rules

JSON has no root element, no attributes and no element names for array items, so a few conventions are needed to produce a well-formed XML document:

  • A root element (named root by default) wraps the whole document, because an XML document must have exactly one root.
  • Each object property becomes a child element named after the property. Names that are not valid XML names are sanitized: invalid characters are replaced by _ and a name that does not start with a letter or underscore is prefixed with _ ("first name"<first_name>, "1st"<_1st>).
  • An array property becomes an element named after the property that contains one <element> (configurable) per array entry: "items": [1, 2]<items><element>1</element><element>2</element></items>. A top-level array produces <element> children directly under the root.
  • Strings, numbers and booleans become the text content of their element. Reserved characters (<, >, &) are escaped automatically, so the output is always well-formed.
  • null becomes an empty element (<property/>). An empty object also produces an empty element.
  • With "Attributes from properties starting with @", a property such as "@id": 1 becomes the attribute id="1" of the enclosing element and the "#text" property becomes its text content — the inverse of the XML to JSON converter.
  • Property order is preserved. Control characters that are not allowed in XML 1.0 are removed from the text.

Example

Input JSON:

{
   "anObject": {
      "numericProperty": -122,
      "stringProperty": "An offensive <tag> & more",
      "nullProperty": null,
      "booleanProperty": true
   },
   "arrayOfObjects": [ { "item": 1 }, { "item": 2 } ],
   "arrayOfIntegers": [ 1, 2, 3 ]
}

Output XML:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <anObject>
      <numericProperty>-122</numericProperty>
      <stringProperty>An offensive &lt;tag&gt; &amp; more</stringProperty>
      <nullProperty/>
      <booleanProperty>true</booleanProperty>
   </anObject>
   <arrayOfObjects>
      <element>
         <item>1</item>
      </element>
      <element>
         <item>2</item>
      </element>
   </arrayOfObjects>
   <arrayOfIntegers>
      <element>1</element>
      <element>2</element>
      <element>3</element>
   </arrayOfIntegers>
</root>

With "Attributes from properties starting with @" enabled, { "cd": { "@id": "1", "#text": "Empire Burlesque" } } gives <root><cd id="1">Empire Burlesque</cd></root>.