JSON to XML
What is a Json To Xml?
Many enterprise systems, SOAP web services, payment gateways, government portals and RSS feeds still expect XML, while modern code works with JSON. This converter turns a JSON document into well-formed XML so you can bridge the two worlds without writing a serializer.
How to use it
- Paste a JSON object or array.
- Copy the generated XML.
- Rename the root element if the receiving system expects a specific name.
Example
Input (double quotes in real JSON):
{ 'order': { 'id': 1001, 'customer': 'Asha', 'items': [ { 'sku': 'A1', 'qty': 2 }, { 'sku': 'B7', 'qty': 1 } ] } }Output:
<order>
<id>1001</id>
<customer>Asha</customer>
<items>
<sku>A1</sku>
<qty>2</qty>
</items>
<items>
<sku>B7</sku>
<qty>1</qty>
</items>
</order>How JSON maps to XML
- Each key becomes an element and its value the element's content.
- Arrays become repeated elements with the same name.
- XML needs exactly one root element; if the JSON has several top-level keys, they are wrapped in a root element.
- Special characters
<,>and&in values are escaped.
Differences to keep in mind
- Types disappear: XML text has no number or boolean type unless a schema (XSD) defines it.
- Attributes vs. elements: generic converters produce elements. If a system needs attributes, such as
<item sku='A1'/>, adjust the output. - Invalid names: keys that start with a digit or contain spaces are not valid XML element names and must be renamed.
- Empty arrays and nulls may become empty elements or be omitted.
Frequently Asked Questions
How are JSON arrays converted to XML?
Each array item becomes a repeated element with the same name.
Why does the output have an extra root element?
XML documents must have exactly one root element, so multiple top-level keys are wrapped.
Can I produce XML attributes instead of elements?
Generic conversion produces elements. Adjust the output by hand or in code if your system expects attributes.
Which JSON keys are invalid in XML?
Keys starting with a digit or containing spaces and most punctuation are not valid element names and need renaming.