How to convert XML to JSON
- Paste XML into the left box, drop an .xml file on it, or press Upload. RSS feeds, SOAP responses, sitemaps and SVG files all work.
- The JSON appears as you type. If the XML isn't well-formed, the status line shows the problem with its line and column.
- Set the attribute prefix and text key, and choose whether to use arrays everywhere, detect numbers or strip namespace prefixes.
- Copy or Download .json. To dig through a big result, open it in the JSON viewer.
XML to JSON example
A small feed with attributes and repeated elements:
<?xml version="1.0" encoding="UTF-8"?>
<feed updated="2026-09-25">
<entry id="1">
<title>Release 2.4</title>
<tag>release</tag>
<tag>api</tag>
</entry>
<entry id="2">
<title>Maintenance window</title>
<tag>ops</tag>
</entry>
</feed>converts to:
{
"feed": {
"@_updated": "2026-09-25",
"entry": [
{
"@_id": 1,
"title": "Release 2.4",
"tag": [
"release",
"api"
]
},
{
"@_id": 2,
"title": "Maintenance window",
"tag": "ops"
}
]
}
}Attributes come first with the @_ prefix, id="1" became the number 1, and the two <entry> elements became an array. The first entry's two tags are an array, but the second entry's single tag is a plain string.
Repeated elements and arrays
XML doesn't say whether an element is "a list", so the converter decides from the data: once is a value, twice or more is an array. If your code needs a stable shape, tick Always use arrays and every element becomes an array, even when it appears once:
{"feed":[{"entry":[{"tag":["ops"]}]}]}Attributes, text, namespaces and CDATA
This product entry uses a namespace prefix, an attribute next to text, a CDATA section and a comment:
<product xmlns:g="http://base.google.com/ns/1.0">
<g:id>0012</g:id>
<price currency="EUR">19.90</price>
<desc><![CDATA[Fits <b>A4</b> & Letter]]></desc>
<!-- internal note -->
</product>{
"product": {
"@_xmlns:g": "http://base.google.com/ns/1.0",
"g:id": "0012",
"price": {
"@_currency": "EUR",
"#text": 19.9
},
"desc": "Fits <b>A4</b> & Letter"
}
}- Namespaces:
g:idkeeps its prefix, and thexmlns:gdeclaration is kept as an attribute. - Text plus attributes: the price text goes under
#text, next to@_currency. - CDATA: the content is kept exactly, including
<b>and&. - Leading zeros:
0012stays a string;19.90becomes the number 19.9. - Comments are dropped.
With Strip namespace prefixes ticked and Detect numbers & booleans unticked, the same XML gives:
{"product":{"id":"0012","price":{"@_currency":"EUR","#text":"19.90"},"desc":"Fits <b>A4</b> & Letter"}}Fixing XML errors
The XML is checked before it is converted. Here the <item> tag is never closed:
<order>
<item>Pen
</order>The converter stops with: Invalid XML: Expected closing tag 'item' (opened in line 2, col 3) instead of closing tag 'order'. (line 3, column 1). Other frequent causes are a bare & (write &), attribute values without quotes, and text before the first tag.
Security: DOCTYPE and entities
XML parsers that expand entities can be tricked into reading local files (XXE) or into huge expansions ("billion laughs"). This converter ignores the DOCTYPE entirely and never expands entities declared in it. It decodes only the standard entities (&, <, >, ", ') and numeric references like é. And because everything runs in your browser, the XML never leaves your device.
Going back to XML
The JSON to XML converter uses the same @_ and #text conventions, so edited JSON converts back into equivalent XML. Mixed content, where text and child elements alternate (<p>Hi <b>you</b> there</p>), is the exception: JSON objects have no order between text and children, so that text is joined. Before converting JSON back, you can format and validate the JSON.
Frequently asked questions
How do I convert XML to JSON?
Paste the XML into the left box or upload an .xml file. The converter checks that the XML is well-formed and turns it into JSON as you type. Copy the JSON or download it as a .json file.
What happens to XML attributes?
They become keys with a prefix, @_ by default, so id="1" becomes "@_id": 1. The prefix keeps attributes apart from child elements with the same name. Change it (for example to @) or turn attributes off in the options.
Why is one element an object and another an array?
An element that appears once becomes a single value, and an element that repeats becomes an array. That can change from file to file, so if your code expects arrays, tick "Always use arrays" to make every element an array.
What is the #text key?
When an element has attributes (or child elements) and also text, the text goes under #text: <price currency="EUR">19.90</price> becomes {"@_currency": "EUR", "#text": 19.9}. An element with only text becomes a plain value.
How are namespaces handled?
Prefixes are kept by default, so <g:id> becomes "g:id" and xmlns declarations become attributes. Tick "Strip namespace prefixes" to get plain names like "id" instead.
What happens to CDATA sections and comments?
CDATA content is kept exactly as written, without decoding, and merged into the element text. Comments and processing instructions are dropped, and so is the <?xml?> declaration.
Why did 0012 stay a string?
Numbers with leading zeros are kept as text so IDs and codes are not changed. Other numbers and true/false become JSON numbers and booleans; untick "Detect numbers & booleans" to keep every value as a string.
Is it safe to paste XML with a DOCTYPE?
Yes. The DOCTYPE is ignored and no entities from it are expanded, so external entity (XXE) and "billion laughs" tricks do nothing. Only the five standard XML entities and numeric character references are decoded.
Is my XML uploaded anywhere?
No. The XML is parsed in your browser and nothing is sent to a server or saved. Only your option choices are remembered on your device.