XML to JSON Converter
Paste XML or open a file and get clean, predictable JSON: attributes are kept as @keys, repeated elements turn into arrays, and numbers and booleans come out as real JSON types.
XML to JSON Converter
Runs in your browser — nothing you enter is uploaded or stored.
Scratchpad auto-saved
How it works — in four simple steps
No signup and nothing to install — it all runs in your browser.
Add your XML
Paste it into the left box, press Open file, or drag a .xml file onto it. Sample loads a realistic example.
Set the options
Adjust the options above the boxes — the output updates instantly as you change them.
Check the result
Read the status line: it reports rows, keys and any value that couldn't be represented in JSON.
Copy or download
Copy the JSON or download it as a .json file. Nothing was uploaded at any point.
Feeding the JSON to code? Tick Always make arrays so a list with a single entry still comes out as an array.
Features
Attributes kept, clearly marked
XML attributes become keys with an @ prefix (or _ / - / none), so they never collide with child elements of the same name.
Real types, not just strings
Numbers, booleans and empty values are detected — while codes with leading zeros such as 00742 or +44 phone numbers stay text.
Namespace control
Keep prefixes like dc:title, or strip them to get plain keys when the namespaces don't matter to you.
Stable array shape
Optionally make every child element an array, so code doesn't break when a list happens to have only one entry.
Pretty or minified
2 or 4 spaces, tabs, or a minified single line for the smallest possible file.
Private by design
Parsing and conversion run in your browser with JavaScript — your data is never uploaded, logged or stored.
About the XML to JSON Converter
XML and JSON both describe trees, but they disagree on the details. XML has attributes and mixed text; JSON has neither. XML can repeat an element name any number of times; JSON keys must be unique. XML has no data types at all — <year>1988</year> is just text — while JSON distinguishes 1988 from "1988". Any XML-to-JSON converter has to pick a convention for each of these, and the choice decides whether the JSON is pleasant to use.
This converter uses the convention most libraries settled on (it matches the default of popular parsers such as fast-xml-parser and xmltodict): each element becomes a key; attributes become keys with an @ prefix; when an element has attributes and text, the text goes into #text; and when the same child name appears more than once, the values are collected into an array in document order. Comments and processing instructions are dropped, CDATA is read as ordinary text, and entity references like & are decoded.
The one convention that bites people is the array rule: a <book> that appears twice becomes an array, but if it appears once it's a plain object — so code that does data.store.book.forEach breaks on a store with one book. Tick Always make arrays when you're feeding the JSON to code and need a stable shape. The XML is parsed by your browser's own standards-compliant parser, so a malformed document is reported with the parser's message instead of being silently half-converted.
Examples
An RSS 2.0 feed is the classic real-world case: a channel with metadata, a namespaced author field, and a list of repeated <item> elements with attributes.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>ToolFeather Blog</title>
<link>https://toolfeather.com/blog/</link>
<item>
<title>How to convert XML to JSON</title>
<guid isPermaLink="false">post-101</guid>
<dc:creator>Pratik</dc:creator>
<pubDate>Tue, 20 Oct 2026 09:00:00 GMT</pubDate>
</item>
<item>
<title>CSV quoting rules explained</title>
<guid isPermaLink="false">post-102</guid>
<dc:creator>Pratik</dc:creator>
<pubDate>Mon, 19 Oct 2026 09:00:00 GMT</pubDate>
</item>
</channel>
</rss>{
"rss": {
"@version": 2,
"channel": {
"title": "ToolFeather Blog",
"link": "https://toolfeather.com/blog/",
"item": [
{
"title": "How to convert XML to JSON",
"guid": {
"@isPermaLink": false,
"#text": "post-101"
},
"creator": "Pratik",
"pubDate": "Tue, 20 Oct 2026 09:00:00 GMT"
},
{
"title": "CSV quoting rules explained",
"guid": {
"@isPermaLink": false,
"#text": "post-102"
},
"creator": "Pratik",
"pubDate": "Mon, 19 Oct 2026 09:00:00 GMT"
}
]
}
}
}This output was produced by the converter on this page with Strip namespace prefixes switched on — load it with the “RSS feed” preset above and change any option to see the effect.
How XML maps to JSON
| In XML | Becomes in JSON |
|---|---|
<title>Dune</title> | "title": "Dune" |
Attribute id="7" | "@id": 7 (prefix is configurable) |
Text next to attributes <price cur="USD">9</price> | "price": {"@cur": "USD", "#text": 9} |
Two or more <item> siblings | "item": [ … ] in document order |
Empty element <note/> | "note": "" |
<![CDATA[a < b]]> | the plain string "a < b" |
Namespace prefix dc:creator | kept as "dc:creator", or "creator" with Strip namespaces |
Comments and <?xml?> | dropped — JSON has no place for them |
Things that trip people up
- One item isn't an array. A single
<entry>becomes an object, two become an array. Turn on Always make arrays if your code loops over the result. - Leading zeros and long IDs. Type detection turns
42into a number but leaves00742, phone numbers and 16+ digit IDs as strings, so nothing is silently corrupted. Untick Detect numbers if you want every value as text. - Trailing zeros on prices.
45.50becomes the number 45.5 — JSON numbers don't keep formatting. If the exact text matters (money, versions), untick Detect numbers. - Mixed content. Prose like
<p>Hello <b>world</b>!</p>can't be represented faithfully as keys; the text parts are joined into#textandbbecomes a key. Convert documents like XHTML with an HTML tool instead. - Entities from a DTD. Only the five predefined XML entities and numeric references are decoded; custom entities declared in an external DTD are not loaded (browsers never fetch external DTDs).
XML vs JSON at a glance
| Property | XML | JSON |
|---|---|---|
| Specification | XML 1.0 Fifth Edition (W3C, 2008) | RFC 8259 (2017) · ECMA-404 |
| File extension | .xml | .json |
| Media type | application/xml (RFC 7303) | application/json |
| Data types | text only (types come from a schema) | string, number, boolean, null, object, array |
| Comments | Yes <!-- --> | No |
| Nesting | Unlimited | Unlimited |
- XML: A document has exactly one root element; element names can't start with a digit, and only five entities (& < > " ') are predefined.
- JSON: Numbers are parsed as IEEE-754 doubles in JavaScript, so integers above 9,007,199,254,740,991 (2⁵³ − 1) lose precision.
Frequently asked questions
5 answersHow are XML attributes converted to JSON?
<book isbn="123"> gives {"@isbn": 123}. You can switch the prefix to _ or -, or remove it, in the options.