Turn XML into Easy-to-Use JSON
If you build web or mobile apps, JSON is probably your default data format — JavaScript reads it natively and every modern framework supports it. But data often arrives as XML: RSS feeds, sitemaps, SOAP API responses, exports from older software or government data files. This converter reads XML and produces clean, formatted JSON you can drop straight into your code.
How to Use the XML to JSON Converter
- Paste your XML into the input panel, or click Load Sample.
- Click Convert to JSON.
- Copy the JSON from the output panel.
If the XML is not well-formed — for example a missing closing tag or an unescaped & — you’ll get an error. Our XML Formatter can help locate the problem.
Example
XML input:
<library>
<book id="1">
<title>Godaan</title>
<author>Premchand</author>
</book>
<book id="2">
<title>Gitanjali</title>
<author>Rabindranath Tagore</author>
</book>
</library>
JSON output:
{
"library": {
"book": [
{ "@id": "1", "title": "Godaan", "author": "Premchand" },
{ "@id": "2", "title": "Gitanjali", "author": "Rabindranath Tagore" }
]
}
}
Because <book> appears twice, the converter groups both into an array, and each id attribute becomes an @id key.
How XML Maps to JSON
| XML | JSON |
|---|---|
| Root element | Top-level key |
| Child element | Nested key |
| Element text | String value |
| Repeated elements | Array |
Attribute id="7" | Key "@id": "7" |
| Text alongside attributes | Key "#text" |
Tips for Working with Converted Data
- Convert types: values like
"10"and"true"are strings. UseNumber()or a comparison in your code. - Normalise arrays: if an element might appear once or many times, wrap single values in an array so your loops always work:
[].concat(data.library.book). - Watch namespaces: prefixed tags such as
<media:content>in feeds keep their prefix in the key name. - Large files: for very large XML files or automated pipelines, use a library in your backend (for example
simplexml_load_stringin PHP orxmltodictin Python).
Common Use Cases
- Showing blog or news RSS items in a React or Vue app.
- Reading SOAP API responses in a JavaScript front end.
- Migrating data from legacy systems to a modern database.
- Inspecting a sitemap’s URLs as a list.
Related Tools
- JSON to XML — convert back to XML.
- JSON Formatter — beautify the converted output further.
- JSON to CSV — open the data in a spreadsheet.