🛠️ Developer & Web

JSON to XML Converter

Turn JSON into clean, valid XML.

  • 1root element, always
  • @default attribute prefix
  • #textelement text key
  • 3indent choices

How to use the JSON to XML

  1. 1

    Paste JSON

    An object, an array or even a single value; the sample shows an order with attributes.

  2. 2

    Set the root and item names

    Leave Root element as “root” to reuse a single top-level key, or type the name the receiving system expects.

  3. 3

    Choose the attribute prefix

    Keys starting with @ (or _) become attributes; pick “(none)” to turn every key into an element.

  4. 4

    Copy or download

    Keep or drop the XML declaration, then copy the result or save converted.xml.

Features

Smart root

If your JSON has exactly one top-level key holding an object, that key becomes the root element instead of a wrapper.

Attributes from keys

Keys like "@currency" become currency="INR" on the parent element.

Repeated elements

Arrays become one element per item, each named after the array’s key.

Escaping

&, < and > in text and quotes in attributes are escaped, so the output stays well-formed.

Safe names

Characters not allowed in XML names become underscores, and names starting with a digit get a leading underscore.

No upload

Conversion happens in your browser.

Who uses it — and for what

Government and banking integrations

Build XML request bodies for portals and gateways that still require XML.

SOAP services

Draft the payload part of a SOAP message from JSON test data.

Feeds and sitemaps

Generate product feeds or sitemap entries from a JSON export.

Testers

Create XML fixtures from JSON you already have.

How JSON becomes XML

Every key becomes an element and nested objects become nested elements. Arrays turn into repeated elements with the key’s name ("tag": ["a","b"] → <tag>a</tag><tag>b</tag>). Keys starting with the attribute prefix (@id) become attributes, and a #text key sets the element’s text. Characters such as & and < are escaped, and key names that aren’t valid XML names (spaces, leading digits) are made safe automatically.

When you need XML

Many enterprise systems, SOAP services, payment gateways, government portals and older APIs still require XML. This converter is useful for building request bodies, test fixtures, sitemaps or feeds from JSON data. XML needs exactly one root element, so a wrapper element is added around your data — rename it to whatever the receiving system expects.

Everything runs in your browser — your code and data are never uploaded, so it is safe to paste private config files and API responses.

Where JSON and XML do not line up

JSON and XML describe data differently, so every converter has to make choices. Knowing this tool’s choices helps you shape the JSON so the XML comes out the way a partner system expects.

JSON featureWhat the converter writesWhat to watch
Numbers, booleansPlain text, e.g. <qty>3</qty>XML has no types; the receiver or its XSD decides
nullAn empty element, <remarks/>Some systems want the element left out, or xsi:nil="true"
Array of valuesRepeated elements with the key’s nameThere is no wrapper element unless you add one in the JSON
Array inside an arrayFlattened: {"b":[1,[2,3]]} becomes three <b> elementsThe nesting is lost — wrap inner arrays in objects
Key orderKept as writtenMany XSDs use xs:sequence, so order can matter
AttributesOnly from prefixed keysValues are always written as text

Preparing JSON for a strict XML consumer

Systems that accept XML often validate it against an XSD schema, and the error messages they send back are rarely friendly. A little preparation saves a lot of back-and-forth:

  • Match names exactly. XML is case-sensitive, so InvoiceNo and invoiceNo are different elements. Rename keys in JSON before converting rather than editing the XML afterwards.
  • Decide attribute versus element. If the specification shows <line hsn="6109">, use an @hsn key; if it shows <hsn>6109</hsn>, use a plain key.
  • Format values as text. Dates, decimals with fixed places ("450.00") and leading zeros should be strings in your JSON, because a JSON number like 450.00 is written as 450.
  • Namespaces. Add them as attributes, e.g. "@xmlns": "urn:example:invoice" or "@xmlns:gst": "…", and use prefixed keys such as "gst:rate" for elements.

After converting, run the result through the XML Validator to confirm it is well-formed. To go the other way, XML to JSON uses the same @ and #text conventions.

Worked examples

A GST-style invoice

Input (abridged):

{"invoice": {
  "@number": "INV-2026-114", "@currency": "INR",
  "seller": {"name": "Sharma Traders", "gstin": "27ABCDE1234F1Z5"},
  "line": [{"@hsn": "6109", "desc": "Cotton T-shirt", "qty": 3, "rate": 450},
           {"@hsn": "4820", "desc": "Notebook <A5>", "qty": 10, "rate": 60}],
  "terms & notes": "Pay within 15 days",
  "2fa": true,
  "remarks": null,
  "amountInWords": {"@lang": "en", "#text": "Two thousand one hundred fifty"}}}

Output with default settings:

<?xml version="1.0" encoding="UTF-8"?>
<invoice number="INV-2026-114" currency="INR">
  <seller>
    <name>Sharma Traders</name>
    <gstin>27ABCDE1234F1Z5</gstin>
  </seller>
  <line hsn="6109">
    <desc>Cotton T-shirt</desc>
    <qty>3</qty>
    <rate>450</rate>
  </line>
  <line hsn="4820">
    <desc>Notebook &lt;A5&gt;</desc>
    <qty>10</qty>
    <rate>60</rate>
  </line>
  <terms___notes>Pay within 15 days</terms___notes>
  <_2fa>true</_2fa>
  <remarks/>
  <amountInWords lang="en">Two thousand one hundred fifty</amountInWords>
</invoice>

The single top-level key invoice became the root. The space and ampersand in terms & notes each became an underscore, and 2fa gained a leading underscore because XML names cannot start with a digit. Check whether the receiving schema expects those exact names.

A top-level array

Input [{"id":1,"city":"Delhi"},{"id":2,"city":"Mumbai"}] with Root element cities and Array item element city gives:

<cities>
  <city>
    <id>1</id>
    <city>Delhi</city>
  </city>
  <city>
    <id>2</id>
    <city>Mumbai</city>
  </city>
</cities>

Valid XML, but a city inside a city is confusing. Choosing an item name like entry avoids the clash.

Pro tips

  • Set the attribute prefix to “(none)” when your JSON has keys that genuinely start with @ or _ and should stay elements.
  • Untick the declaration when the XML will be embedded inside another document, such as a SOAP envelope.
  • Changing the Root element from “root” disables the single-key shortcut, so your chosen name always wraps the data.

Glossary

Root element
The single top-level element that contains everything else in an XML document.
Attribute
A name="value" pair written inside an element’s start tag.
XML declaration
The optional first line, <?xml version="1.0" encoding="UTF-8"?>, stating version and encoding.
XSD
XML Schema Definition — a file describing which elements, attributes and types a document may contain.

Frequently asked questions

Why is there a root element?

XML documents must have exactly one top-level element.

How do I create attributes?

Prefix the key with @, e.g. {"@id": 5} becomes id="5".

What happens to null values?

They become empty elements like &lt;key/&gt;.

How do I get a wrapper around repeated elements, like <lines><line/></lines>?

Nest the array one level deeper in your JSON: {"lines": {"line": [ ... ]}}.

Can I create CDATA sections?

No. Text is escaped with entities such as &lt; instead, which any XML parser reads back to the same characters.

Why did my key get underscores?

XML element names cannot contain spaces or symbols like &, and cannot start with a digit, so those characters are replaced.

Found it useful? Share the JSON to XML:

Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Developer & Web (77 tools)