Free tool
XML to JSON Converter
Convert XML to JSON with your browser's own XML parser. Attributes, repeated elements and CDATA are handled, and DTDs with entities are refused.
Runs entirely in your browser. Nothing you type or upload is sent to our servers.
How to convert XML to JSON
- Paste XML or press Load example.
- Choose how attributes and text are named, and whether to detect numbers and booleans.
- Copy the JSON or download it.
Worked example
This XML has an attribute on the root, two repeated book elements and an empty element:
<library name="City">
<book id="1"><title>Dune</title></book>
<book id="2"><title>Emma</title></book>
<open/>
</library>The root attribute gets the @ prefix, the repeated book elements become an array, and the empty open element becomes null:
{
"library": {
"@name": "City",
"book": [
{
"@id": "1",
"title": "Dune"
},
{
"@id": "2",
"title": "Emma"
}
],
"open": null
}
}With type detection on, <item id="7" on="true">3.50</item> gives the following. The attribute values become a number and a boolean, but 3.50 stays text because writing it as a number would print 3.5:
{
"item": {
"@id": 7,
"@on": true,
"#text": "3.50"
}
}Rules the converter follows
- Browser parser. Parsing uses your browser's own XML parser, so well-formedness errors come from the browser.
- No DTDs. Input with a DOCTYPE or ENTITY declaration is refused.
- Limits. Up to 2,000,000 characters and 200 levels of nesting.
- Safe keys. Element names such as
__proto__become ordinary JSON keys.
Going the other way? Format the result with the JSON formatter, flatten it with JSON to CSV, or convert a YAML config with YAML to JSON. Need to see the markup rendered? Use the HTML viewer.
Frequently asked questions
Is my XML uploaded?
No. The XML is parsed by the XML parser built into your browser and converted to JSON by JavaScript on the same page. Nothing is sent to a server or stored, so it is reasonable to paste internal feeds and configuration files, as long as you remove secrets you do not want on screen.
How are attributes and text represented?
Attributes become keys that start with a prefix, "@" by default, so id="1" becomes "@id": "1". An element that has only text becomes a string. An element that has attributes or child elements and also text keeps the text under a key, "#text" by default. Both names can be changed.
What happens when an element repeats?
When sibling elements share a name, such as several book elements, they become a JSON array in document order. A name that appears once stays a single value, so the shape can differ between documents. If your code expects an array every time, wrap single values in an array after converting.
Why was my XML rejected because of a DOCTYPE?
A DOCTYPE can declare entities that expand into very large text, which can freeze a browser tab. This converter refuses any input containing a DOCTYPE or ENTITY declaration and shows a message. Delete the DTD part, keep the elements, and convert again. Standard character references such as & and < still work.
Are numbers and booleans converted?
Not unless you ask. By default every value stays a string, which never changes data. If you tick the option to detect types, true and false become booleans and plain numbers become JSON numbers, but a value such as 007 or 1.50 stays text because converting it would change how it prints.
What is lost in the conversion?
Comments and processing instructions are skipped. When an element mixes text and child elements, the text pieces are joined into one string and the position of the text between children is not kept. Namespace prefixes stay as written in the element and attribute names, for example "dc:title".
What does an error message look like?
If the XML is not well formed, for example a missing closing tag, the page shows the message your browser's parser reports, usually with a line and column. Fix that spot and the result appears as soon as the XML parses. Input up to 2,000,000 characters is accepted.
Link to this tool
Found it useful? Copy a link for your page, newsletter or documentation.
Get new tools and guides by email
Optional. The tool above works without signing up.
More free tools
Browse all developer tools or the full list of free tools.
- CSS Gradient GeneratorBuild linear and radial CSS gradients with a live preview, up to eight color stops and opacity, then copy the CSS. Nothing is uploaded or stored.
- CSS Box Shadow GeneratorDesign a CSS box shadow with sliders, stacked layers, inset shadows and opacity, see it live, and copy the box-shadow CSS. Runs entirely in your browser.
- chmod Calculator (Octal and Symbolic)Convert Unix file permissions between octal like 755 and symbolic like rwxr-xr-x, apply symbolic changes, and copy the chmod command. Runs in your browser.
- Password & API Key GeneratorGenerate strong random passwords and API keys with your browser's cryptographic random number generator. Nothing is sent or stored.
- Barcode Generator (Code 128, EAN-13, UPC-A)Create Code 128, EAN-13 and UPC-A barcodes with the check digit calculated for you, then download SVG or PNG. Input is validated and stays in your browser.
- Emoji Copy and PasteSearch about 1,900 emoji by name or keyword, browse them by category, and copy any of them with one click. The emoji you pick are never sent anywhere.