JSONToonPro
JSON converter tool

JSON to XML Converter Online

Convert JSON objects, arrays, and API responses to clean XML in one click, or switch directions and parse XML back to JSON. Set root and item tags, preserve attributes, include the XML declaration, and download a ready to use file. All conversion happens locally in your browser.

100% client sideXML to JSONCopy and download
Indent
40 nodes
Input/ JSON
548 chars26 lines
Output/ XML
645 chars25 lines

The Mapping Rules

JSON and XML both describe trees, so the conversion is more natural than flattening to a spreadsheet. Three rules cover almost every case.

  • An object key becomes an element name, and the value becomes that element's content.
  • An array becomes a set of repeated sibling elements sharing one name, because XML has no array literal. The array itself is invisible in the output.
  • A primitive becomes text content. Numbers and booleans lose their type and become plain characters, since XML without a schema has no types.

The array rule is the one with consequences. Since the brackets vanish, an array of one element and a bare object produce identical XML. That ambiguity is why converting back from XML to JSON needs either a schema or a convention.

Side by Side Example

A small product catalogue, shown as JSON and as the XML it produces.

JSON input

{
"catalogue": {
"updated": "2025-03-01",
"product": [
{ "sku": "TT-100",
"name": "Tea & Toast set",
"price": 18.99 },
{ "sku": "MG-204",
"name": "Mug <large>",
"price": 7.5 }
]
}
}

XML output

<?xml version="1.0" encoding="UTF-8"?>
<catalogue>
<updated>2025-03-01</updated>
<product>
<sku>TT-100</sku>
<name>Tea &amp; Toast set</name>
<price>18.99</price>
</product>
<product>
<sku>MG-204</sku>
<name>Mug &lt;large&gt;</name>
<price>7.5</price>
</product>
</catalogue>

Element Naming Constraints

JSON keys are arbitrary strings. XML element names are not, and this is where most conversions actually break. An XML name must start with a letter or an underscore, may not start with a digit, may not contain spaces, and may not begin with the sequence xml in any casing, which is reserved.

JSON keyValid element?Typical transformation
firstNameYesfirstName, used unchanged
first nameNo, spacefirst_name or firstName
1stNo, leading digit_1st or n1st
order-totalYesHyphens are legal after the first character
user.idYes but riskyFull stops are legal but read as a path by some tooling
xmlDataNo, reserved prefixx_xmlData
(empty string)Noitem or a positional fallback
price (£)No, space and symbolprice_gbp

Pick one transformation policy and apply it consistently, because the mapping needs to be predictable if anything downstream will parse the result.

Attributes Versus Child Elements

This is the design decision with no correct answer, and JSON gives you no hint either way because it has only keys and values. The same data can be modelled both ways.

Two valid encodings of the same record

<product sku="TT-100" price="18.99">
<name>Tea set</name>
</product>
 
<product>
<sku>TT-100</sku>
<price>18.99</price>
<name>Tea set</name>
</product>

The usual guidance is that attributes carry metadata about the element (identifiers, units, language codes, flags) while child elements carry the content itself. Attributes cannot repeat, cannot nest, and cannot hold structure, so anything that might grow later belongs in an element. Converters default to all elements because it is the only choice that never loses the ability to expand a value into a subtree.

Declaration, Escaping, and the Single Root

A well formed XML document conventionally opens with a declaration naming the version and the character encoding. It is optional in XML 1.0 but including it removes any doubt about how the bytes should be decoded.

Five characters have special meaning inside XML and must be replaced with their predefined entities when they appear in text content.

CharacterEntityRequired in
<&lt;Text content and attribute values
>&gt;Text content, recommended everywhere
&&amp;Text content and attribute values
"&quot;Attribute values quoted with double quotes
'&apos;Attribute values quoted with single quotes

Missing the ampersand is the classic failure. A company name such as Marks & Spencer produces a fatal parse error, not a warning, because the parser reads the ampersand as the start of an entity reference.

Exactly one root element

XML requires a single outermost element. JSON has no such rule, so a top level array has nowhere to go and needs a synthetic wrapper. An array of three orders becomes an orders element containing three order elements. Choose the wrapper name deliberately, since it becomes part of the contract for anything reading the document, and a generic name like root tells the consumer nothing.

XML is rarely the last stop. Explore the full converter collection for XML to JSON to reverse the transformation, JSON to YAML when the target is a config file rather than a document, and JSON Schema when you need validation rules similar to what an XSD would give you.

How to convert JSON to XML

Three steps, zero setup
01

Paste JSON or upload a file

Add an object, array, API response, or data export. Use the sample button to see attributes and repeated XML elements.

02

Choose XML structure

Set root and array item names, choose indentation, and include or remove the XML declaration.

03

Copy or download XML

Output updates live as you type. Copy the XML or download a ready to use .xml file.

Built for structured data exchange

Turn JSON API data into XML for legacy integrations, feeds, import jobs, SOAP-style workflows, and schema-driven systems without exposing the payload.

100% client side

Private payloads stay in your browser. No uploads, storage, or server processing.

Instant conversion

Generate XML live with useful errors for invalid JSON or malformed XML.

XML controls

Edit root tags, item tags, indentation, and XML declaration output.

Attributes supported

Use @ keys for XML attributes and #text for text mixed with child elements.

XML to JSON

Parse XML back into structured JSON with attributes and repeated elements preserved.

XML workflow

Copy XML or download a ready to use file for integrations and imports.

Frequently asked questions

7 answers
Paste valid JSON into the input panel or upload a .json file. The XML output is generated instantly. You can choose the root tag, array item tag, indentation, XML declaration, then copy or download the result.

XML to JSON Converter

Need to convert XML back to JSON? Use the XML to JSON tab or click Swap. Paste any XML document and get structured JSON output instantly. Attributes are preserved with @ prefixes and text content with #text so the conversion is lossless.

More JSON Tools