Skip to content
Devtoolry

JSON to XML

Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the JSON to XML

The JSON to XML converter produces well-formed XML from JSON, with a root element you choose. Arrays become repeated elements, which is how most XML formats represent lists.

Conversion happens in your browser, so your files and records stay private.

How to use the JSON to XML

  1. Paste JSON.
  2. Set the root element name and indentation.
  3. Copy or download the XML.

Example

Build an XML order with attributes

Input

{
  "order": {
    "@_id": "1042",
    "customer": "Ada Lovelace",
    "item": [
      { "@_sku": "A-1", "#text": "Notebook" },
      { "@_sku": "B-7", "#text": "Pen" }
    ]
  }
}

Result

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <order id="1042">
    <customer>Ada Lovelace</customer>
    <item sku="A-1">Notebook</item>
    <item sku="B-7">Pen</item>
  </order>
</root>

Keys starting with @_ become attributes, #text becomes the element’s text and the item array becomes repeated <item> elements.

Common mistakes

  • An extra root element. XML allows only one root, so the whole JSON is wrapped in the root element you set (root by default). To make <order> the root, paste only the inner object and set the root name to order.
  • Keys that are not valid XML names. Names cannot start with a digit or contain spaces. Such keys are adjusted to stay well-formed, so check them if a consumer expects exact names.
  • Expecting a specific schema. The converter maps JSON structure to XML generically. A format with a fixed schema (SOAP, UBL, sitemaps) may need renamed elements or namespaces.

Works well with the JSON to XML

Frequently asked questions

How are invalid element names handled?

JSON keys that are not valid XML names (for example ones starting with a digit) are adjusted so the output stays well-formed.

Can I create XML attributes?

Yes. Keys that start with @_ become attributes, so { "book": { "@_id": "1" } } produces <book id="1">.

How are null values written?

As empty elements, such as <middleName/>, so the element is still present.

Are special characters escaped?

Yes. &, < and > in values are escaped, so the output is always well-formed.

Guides and tutorials