JSON to XML Converter

Paste JSON and get indented, well-formed XML for a SOAP request, a legacy import or an XML-only API. Your data is converted locally and never sent to a server.

JSON → XML

Input

Settings

History

Load from URL

Why generate XML from JSON

Modern services produce JSON, but many integrations still demand XML: SOAP endpoints, EDI and banking gateways, government filing systems, RSS and sitemap files, and enterprise middleware. Converting by hand means escaping & and <, inventing element names and keeping tags balanced. This tool does that mechanically and reports every decision it had to make.

How JSON becomes elements

  • Each object key becomes a child element, and the value becomes its content.
  • An array repeats the element once per item: {"tag": ["a", "b"]} produces <tag>a</tag><tag>b</tag>.
  • Arrays with no natural name — a top-level array or an array nested directly inside another array — produce elements named after the Array item element option.
  • Keys starting with @ become attributes on the parent: {"order": {"@id": "1"}} gives <order id="1">.
  • A #text key becomes the element’s text and #cdata becomes a CDATA section, mirroring the convention used by XML to JSON.
  • Numbers and booleans are written as text, with numbers keeping their exact source digits.
  • null, empty strings and empty objects all produce an empty element such as <note/>. An empty array produces no element at all.
  • Text is escaped (&amp;, &lt;), and carriage returns are written as &#13; so they survive parsing.

Options

Root element (default root) names the wrapper element. If your JSON is an object with exactly one key whose value is not an array — like {"order": {...}} — that key becomes the root instead and this option is not needed. Anything else, including objects with several keys, top-level arrays and plain values, is wrapped in the root element.

Array item element (default item) names the elements created for unnamed array entries, for example <item> for each row of a top-level array. Set it to row, record or whatever the receiving schema expects.

XML declaration (on by default) adds <?xml version="1.0" encoding="UTF-8"?> as the first line. Turn it off when the XML will be embedded inside another document or a SOAP envelope.

Names that XML rejects

JSON keys can be anything; XML names cannot start with a digit or contain spaces and most punctuation. Invalid characters are replaced with _, and a leading digit gets an underscore prefix: "first name" becomes <first_name> and "2fa" becomes <_2fa>. An info message lists every renamed key. Control characters that XML 1.0 cannot represent at all are replaced with U+FFFD and reported as a warning. An attribute key whose value is an object or array is written as JSON text inside the attribute.

What XML cannot record

XML has no types and no difference between a one-item array and a single value, so {"tag": ["x"]} and {"tag": "x"} produce identical XML. null and "" also become the same empty element. If the receiving side needs that information, use an XML Schema on its side. Check the result in the XML formatter; the conversion itself never leaves your browser.

Examples

Customer record with an array

The multi-key object is wrapped in <customer>, and the tags array becomes two sibling <tags> elements.

Input
{
  "id": 1042,
  "name": "Aisha Tan",
  "email": "aisha.tan@example.com",
  "tags": ["admin", "beta"],
  "address": { "city": "Singapore", "postcode": "018956" }
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<customer>
  <id>1042</id>
  <name>Aisha Tan</name>
  <email>aisha.tan@example.com</email>
  <tags>admin</tags>
  <tags>beta</tags>
  <address>
    <city>Singapore</city>
    <postcode>018956</postcode>
  </address>
</customer>
Open this example in the tool

Attributes and text with @ and #text

The single top-level key becomes the root, @ keys become attributes and #text becomes element content.

Input
{
  "order": {
    "@id": "ord_8f2k1",
    "@status": "paid",
    "item": [
      { "@sku": "KB-104", "@qty": "1", "#text": "Mechanical keyboard" },
      { "@sku": "MS-220", "@qty": "2", "#text": "Wireless mouse" }
    ]
  }
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<order id="ord_8f2k1" status="paid">
  <item sku="KB-104" qty="1">Mechanical keyboard</item>
  <item sku="MS-220" qty="2">Wireless mouse</item>
</order>
Open this example in the tool

Top-level array of rows

Each row becomes a <product> inside <products>, prices keep their written digits, and “in stock” is renamed to in_stock.

Input
[
  { "sku": "KB-104", "price": 129.90, "in stock": true },
  { "sku": "MS-220", "price": 79.00, "in stock": false }
]
Output
<products>
  <product>
    <sku>KB-104</sku>
    <price>129.90</price>
    <in_stock>true</in_stock>
  </product>
  <product>
    <sku>MS-220</sku>
    <price>79.00</price>
    <in_stock>false</in_stock>
  </product>
</products>
Open this example in the tool

Common errors and how to fix them

ErrorCauseFix
Renamed 2 names that are not valid in XML: "a b" → a_b, "2x" → _2xAn info message: some JSON keys contain spaces or start with a digit.Nothing to do if the new names suit you; otherwise rename the keys in the JSON first.
Replaced 1 character that XML cannot represent with U+FFFDA string contains a control character (such as \u0001) that XML 1.0 forbids.Remove the character from the source data, or encode the value (for example as Base64) before converting.
Object keys must use double quotes, not single quotes
Explained
The input is not strict JSON.Use double quotes, or convert relaxed syntax with JSON5 to JSON first.

Frequently asked questions

How do I create XML attributes from JSON?

Prefix the key with @, for example “@id”: “42”. It becomes id=“42” on the element that owns the object.

What does the Root element option do if my JSON has a single top-level key?

Nothing: that key already names the root. The option only applies when the JSON needs wrapping, such as an object with several keys or an array.

How are null values written?

As an empty element like <note/>, the same as an empty string. XML has no separate null.

Can I leave out the <?xml ?> declaration?

Yes. Switch off XML declaration, which is useful when pasting the result into a SOAP body or another document.

Is my JSON sent anywhere?

No. The page builds the XML in your browser, so it can be used with customer records and internal payloads.

Related tools