XML to JSON Converter
Convert XML to JSON in your browser. Attributes, repeated elements and text follow clear rules, numbers such as zip codes stay text when they should, and errors point to the exact line and column.
XML input
JSON output
Paste XML to see the JSON.
Options
How to convert XML to JSON
- Add your XML. Paste it, drop an .xml file onto the page, or press Load sample. A declaration such as <?xml version="1.0"?> is fine and is skipped.
- Check the JSON. Attributes appear as keys that start with @, elements that repeat become arrays, and text sits in the element itself. If the XML is not well formed you get the line, the column and what was expected.
- Copy or download. Pick a 2 or 4 space indent, or minified, then copy the JSON or save it as a .json file.
There is no convert button. The JSON updates whenever the input or an option changes.
Before
<book id="bk101">
<title>XML Guide</title>
<price currency="USD">44.95</price>
</book>After
{
"book": {
"@id": "bk101",
"title": "XML Guide",
"price": {
"@currency": "USD",
"#text": 44.95
}
}
}How XML maps to JSON
XML and JSON do not describe data the same way. XML has attributes and mixed text, JSON has arrays and numbers. There is no single official mapping, so this converter uses the common convention below and applies it the same way every time.
| In the XML | In the JSON | Example |
|---|---|---|
| Element with only text | A string (or a number or boolean, see the options) | <title>Guide</title> becomes "title": "Guide" |
| Attribute | A key with an @ prefix | id="bk101" becomes "@id": "bk101" |
| Element with attributes and text | An object, with the text under "#text" | <price currency="USD">44.95</price> becomes {"@currency": "USD", "#text": 44.95} |
| Elements that repeat | An array | two <tag> elements become "tag": ["xml", "guide"] |
| Empty element | null, or an empty string if you choose | <e/> becomes "e": null |
| CDATA section | Plain text | <![CDATA[a < b]]> becomes "a < b" |
| Comments, processing instructions, DOCTYPE | Not included |
What this converter does
- Private by design
- The XML is parsed in your browser tab. Nothing is uploaded, so it is safe for feeds and exports that contain customer data.
- Numbers are converted carefully
- With the conversion option on, a value becomes a number only when it is in standard form: no leading zero, no plus sign and at most 15 digits. A zip code such as 01234 and a 17-digit ID stay text, so no data is lost. Turn the option off to keep every value as a string.
- Predictable arrays
- One <item> gives an object and two give an array, which makes the JSON awkward to consume. Tick Always use arrays and a repeated element name is always a list.
- Precise errors
- A closing tag that does not match, a missing quote around an attribute or a bare ampersand is reported with its line and column, and Go to the error selects the spot.
- Related tools
- To go the other way, use JSON to XML. To tidy the result, open it in the JSON Formatter.
What to know before you rely on it
- Mixed content is merged. In text such as
<p>Hello <b>world</b></p>the text around the child element is joined into one#textvalue, so its position between the elements is lost. This suits data files. It does not suit documents such as HTML or word-processing formats. - Namespaces are kept as written. A name like
dc:titlestaysdc:title. The tool does not resolve namespace URIs. - Entities. The five standard entities (& < > " ') and numeric references such as © are decoded. Entities defined in a DOCTYPE are not expanded, and an unknown one is reported as an error.
- A round trip is not guaranteed to be identical. Converting XML to JSON and back can change attribute order, comments and the position of mixed text.
Typical inputs are RSS and Atom feeds, sitemap.xml files, SOAP and older API responses, exported configuration and data from legacy systems.
Frequently asked questions
How do I convert XML to JSON?
Paste the XML into the input box or drop an .xml file on the page. The JSON appears straight away. Pick the indent you want, then press Copy or Download .json.
How are XML attributes converted?
Each attribute becomes a key that starts with @, for example id="bk101" becomes "@id": "bk101". You can change the prefix to an underscore, remove it, or ignore attributes altogether.
Why do some elements become arrays and others do not?
An element that appears once becomes a single value and an element that repeats becomes an array. If you want a consistent shape, tick Always use arrays and every child element is written as a list.
Why is my zip code or ID a string instead of a number?
Because turning it into a number would change it. A value such as 01234 would lose its leading zero, and an ID with more than 15 digits would be rounded by JavaScript. Only values in standard number form are converted. You can also turn the conversion off to keep everything as text.
What happens to XML namespaces?
Prefixed names such as dc:title or xsi:type are kept exactly as written. The tool does not resolve them to URIs.
Is my XML uploaded to a server?
No. The XML is parsed in your browser and never leaves your device.
Does it handle CDATA sections and special characters?
Yes. CDATA content is read as plain text, and the five standard entities and numeric character references are decoded. Entities that are defined in a DOCTYPE are not expanded.
What does the error message mean when I paste XML?
The XML is not well formed. Common causes are a closing tag that does not match the opening tag, an attribute value without quotes, a bare ampersand that should be written as &, or more than one root element. The message gives the line and column.
Can I convert the JSON back to XML?
Yes, with the JSON to XML tool on this site. A round trip may not give back identical XML, because JSON has no comments and does not keep the position of text between elements.