Quick answer
To convert XML to JSON, paste your XML into the XML box. Choose the options: Keep attributes (as @name), Detect numbers & true/false to output real numbers and booleans instead of strings, and Always use arrays (even for single elements) for a predictable structure. Pick the indentation (2, 4 or minified). The JSON appears instantly with the root element as the top-level key. Invalid XML is reported with the parser's message.
- Input:
- Any well-formed XML
- Attributes:
- Kept as @name keys (optional)
- Text:
- #text for elements with attributes and text
- Types:
- Optional number and boolean detection
- Arrays:
- Repeated tags become arrays; option to use arrays for every child element
- Formatting:
- 2 spaces, 4 spaces or minified
- Errors:
- Clear message for invalid XML
- Upload needed:
- No – runs in your browser
XML is everywhere behind the scenes: RSS and Atom feeds, sitemaps, SOAP APIs, payment and shipping integrations, government data portals, product feeds, Android layouts, Microsoft Office files and decades of enterprise systems. But modern front-end code, mobile apps, NoSQL databases and most new APIs work with JSON. Developers constantly need to turn XML into JSON to process, store or display it.
Our XML to JSON converter parses your XML with the browser's standards-compliant XML parser and converts it into well-structured JSON. Child elements become nested objects; elements that appear more than once under the same parent become arrays; text becomes values; and attributes, if you keep them, appear as keys starting with @. When an element has both attributes and text, the text is stored under #text.
Two options solve the most common headaches. Type detection turns "42" into 42 and "true" into true, so you do not have to convert values in code. Always use arrays wraps every child element in an array, even when there is only one — so code that loops over items does not break when a feed happens to contain a single entry.
Everything runs locally in your browser, so private data such as orders, invoices and customer records is never uploaded.
How to convert XML to JSON – step by step
- 1 Paste your XMLPaste a full document or fragment with a single root element.
- 2 Choose optionsKeep attributes if they contain data, enable type detection for numbers and booleans, and always use arrays for predictable lists.
- 3 Pick indentation2 or 4 spaces for reading, minified for storage or transmission.
- 4 Check the resultReview the JSON; errors in the XML are reported with an explanation.
- 5 Copy or downloadCopy the JSON or download it and use it in your code or database.
Why use this XML to JSON converter?
Standards-compliant parsing
Uses the browser's XML parser, which reports malformed XML.
Attributes preserved
Optional @name keys keep every piece of data.
Type detection
Real numbers and booleans in the output.
Predictable arrays
Option to wrap every child element in an array.
Readable or compact
Indented or minified JSON.
Private and free
Runs in your browser, no sign-up.
How XML maps to JSON
| XML | JSON result |
|---|---|
| <name>Rafi</name> | "name": "Rafi" |
| <user><id>7</id></user> | "user": {"id": 7} (with type detection) |
| <tag>a</tag><tag>b</tag> | "tag": ["a", "b"] |
| <price currency="USD">9</price> | "price": {"@currency": "USD", "#text": 9} |
| <empty/> | "empty": null |
| <active>true</active> | "active": true (with type detection) |
The single-item array problem
Without the "always use arrays" option, a feed with two <item> elements becomes an array, but a feed with one <item> becomes a plain object. Code written as data.items.item.forEach(...) then crashes whenever the feed contains just one item — a classic bug in feed integrations. Turning on Always use arrays avoids it: every child element becomes an array, so the same code works for one item or a thousand. Single values are then read as user.id[0], which is more verbose — leave the option off when the structure is fixed and simple.
When to keep or drop attributes
Attributes often carry real data — IDs, currencies, units, dates, links (for example href in Atom feeds or the url attribute in media tags). Keep them when you need that data. If attributes are only technical metadata, such as namespace declarations or schema locations, turning them off produces cleaner JSON. Namespace prefixes are kept in names, so <media:content> becomes "media:content".
Type detection: benefits and pitfalls
Type detection converts values that look like numbers or booleans. That is usually what you want for prices, quantities and flags. But some values look numeric without being numbers: phone numbers with leading zeros, postcodes, product codes, account numbers and very long IDs. The converter skips values that are too long to be safe numbers, but codes such as "0123" would lose their leading zero. If your data contains such values, turn type detection off and convert specific fields in code.
Common uses
- RSS and Atom feeds — convert blog or news feeds for use in apps and widgets.
- Sitemaps — turn sitemap.xml into JSON to analyse URLs (create sitemaps with our Sitemap Generator).
- SOAP and legacy APIs — read XML responses in JavaScript or Python.
- Product feeds — import supplier XML catalogues into a JSON-based shop or database.
- Configuration files — migrate XML config to JSON.
- Debugging — inspect complex XML in a format that is easier to scan.
After converting
Format, validate or minify the JSON further with our JSON Formatter. To go back, the JSON to XML converter uses the same @attribute and #text conventions, so data can round-trip between formats. If the XML came from a website, our HTTP Headers Checker shows the content type and caching headers of the feed URL.
Things XML has that JSON does not
Comments and processing instructions are ignored, because JSON has no place for them. Mixed content — text interleaved with child elements, as in documents — is simplified: the text is joined and child elements become keys, which suits data but not prose. CDATA sections are read as text. Whitespace-only text between elements is ignored. These rules suit data feeds and APIs, which are the main reasons to convert XML to JSON.
Working with the JSON in code
After converting, you can use the data directly. In JavaScript, parse it with JSON.parse and reach values with dot notation — for an RSS feed, something like data.rss.channel.item gives the list of posts. Keys containing colons or the @ sign need bracket notation: item["media:content"]["@url"]. In Python, json.loads gives dictionaries and lists, and the same keys apply. If you will process the same kind of XML regularly, use the converted JSON to design your data model, then write a small parser for production that maps exactly the fields you need — it will be faster and easier to maintain than handling the full generic structure.
Large documents
The conversion runs in your browser and handles documents of several megabytes, limited by memory. For very large files or automated pipelines, use a streaming parser in code — such as Python's lxml or xmltodict, Node's fast-xml-parser or PHP's XMLReader — and use this tool to explore the structure first.
Troubleshooting
- "Invalid XML". The document is not well-formed: an unclosed tag, an unescaped & or <, or more than one root element. The message shows the parser's explanation.
- HTML does not convert. HTML is usually not well-formed XML; this tool is for XML.
- Leading zeros disappeared. Turn off type detection.
- A list became an object. The feed had only one item; turn on Always use arrays.
Frequently asked questions
How do I convert XML to JSON?
Paste the XML, choose your options and copy or download the JSON.
What happens to XML attributes?
With Keep attributes on, they become keys starting with @.
What is #text in the JSON?
The text content of an element that also has attributes.
How are repeated elements handled?
They become arrays. Enable Always use arrays to wrap every child element in an array, even single ones.
Can it detect numbers and booleans?
Yes. Enable Detect numbers & true/false.
Why did my product code lose its leading zero?
Type detection turned it into a number. Turn the option off.
Can I convert RSS feeds?
Yes. Paste the feed's XML to get JSON.
Is my data uploaded?
No. Conversion runs in your browser.
Can I convert HTML?
Only if it is well-formed XHTML. Regular HTML often fails to parse as XML.
Can I convert JSON back to XML?
Yes. Use our JSON to XML converter.
Is the converter free?
Yes. No sign-up required.
How are empty elements converted?
An empty element such as <note/> becomes null; with attributes it becomes an object of those attributes.
Are namespace prefixes kept?
Yes. Elements like media:content keep their prefix in the key name.
Does it keep CDATA content?
Yes. CDATA sections are read as normal text.
Can I minify the JSON output?
Yes. Choose Minified indentation for a compact single line.
Last updated November 21, 2026 · Written and tested by the SmallEasyTools team.