JSON to XML converter

Paste a JSON object to get valid XML for systems that only accept XML, such as some payment and invoicing gateways.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter json text, root element name when needed and add the <?xml ?> declaration.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Each key becomes an element, a key starting with @ becomes an attribute, #text becomes the element text, and each array item becomes a repeated element with the same name. A single-key object supplies the root, otherwise the data is wrapped in the root name you choose. &, <, > and " are escaped.

Example

Inputs: Root element name when needed = root, Add the <?xml ?> declaration = yes. Result: XML: <?xml version="1.0" encoding="UTF-8"?> <order id="1001"> <customer>سارة</customer> <item> <name>قهوة</name> <qty>2</qty> </item> <item> <name>تمر</name> <qty>1</qty> </item> <paid>true</paid> </order>; Elements: 9; Keys renamed to valid XML names: 0.

{"order": {"@id": "1001", "customer": "سارة", "item": [{"name": "قهوة", "qty": 2}, {"name": "تمر", "qty": 1}], "paid": true}}
<?xml version="1.0" encoding="UTF-8"?>
<order id="1001">
  <customer>سارة</customer>
  <item>
    <name>قهوة</name>
    <qty>2</qty>
  </item>
  <item>
    <name>تمر</name>
    <qty>1</qty>
  </item>
  <paid>true</paid>
</order>

Limits and caveats

  • Names that are invalid in XML (with spaces or a leading digit) get their bad characters replaced by _.
  • An object used as an @ attribute value is written as JSON text.

Questions about this tool

How do I add an attribute?

Prefix the key with @, for example "@id": "7", and it appears as id="7" inside the element tag.

What happens to arrays?

Each array item becomes its own element named after the key, so an item key holding two values gives two <item> tags.

Are numbers and booleans kept?

They are written as text, so 2 becomes <qty>2</qty> and true becomes <paid>true</paid>, because XML has no data types.