What it does
The XML to JSON Converter turns XML into JSON while keeping the attributes, and converts JSON back to XML. Use it to work with SOAP or RSS responses, old configuration files or exported data in JavaScript and modern APIs.
How to use it
- Paste XML, open a file, or click Load sample.
- Choose the indent.
- Copy or download the JSON.
- Click Swap direction to turn JSON into XML.
Example
<book id="bk101" lang="en">
<title>XML Guide</title>
<price currency="USD">44.95</price>
<tag>xml</tag>
<tag>dev</tag>
</book>
As JSON:
{
"book": {
"title": "XML Guide",
"price": {
"#text": 44.95,
"@_currency": "USD"
},
"tag": [
"xml",
"dev"
],
"@_id": "bk101",
"@_lang": "en"
}
}
How the mapping works
- Attributes become keys starting with
@_. - When an element has attributes and text, the text is stored under
#text. - Repeated elements become an array.
- Numbers and booleans are converted to JSON numbers and booleans.
FAQ
Why is a single <tag> not an array?
With only one element there is nothing to show it repeats. Code that reads the JSON should accept both a single value and an array.
Can I get typed classes instead of JSON? Use XML to Code for C#, Java, Go or TypeScript.