Input
Ready
Lines: 0
Words: 0
Chars: 0
Size: 0 KB
Input statistics are available via the Stats button above this field.
Output
Lines: 0
Words: 0
Chars: 0
Size: 0 KB
Output statistics are available via the Stats button above this field.
Results are provided for informational purposes only and may contain errors. Please verify important information independently. Use of this tool is at your own risk.
What the XML to JSON Converter does
The XML to JSON Converter parses an XML document and outputs the same data as indented JSON. Elements become keys, attributes become keys prefixed with @_, and repeated elements with the same name become an array.
The XML declaration (<?xml ...?>) is ignored. Text that looks like a number, such as 9.99, is returned as a JSON number rather than a string.
When to use it
- Working with an RSS feed, sitemap, SOAP response or configuration file in JavaScript, where JSON is easier to handle.
- Moving data from an XML-based system into a JSON API or a document database.
- Inspecting a large XML file: the JSON output is often easier to scan, especially after formatting.
Worked example
Input
<catalog>
<book id="b1"><title>Dune</title><price>9.99</price></book>
<book id="b2"><title>Emma</title><price>4.5</price></book>
</catalog>
Output
{
"catalog": {
"book": [
{
"title": "Dune",
"price": "9.99",
"@_id": "b1"
},
{
"title": "Emma",
"price": "4.5",
"@_id": "b2"
}
],
"#text": "\n \n \n"
}
}Common questions about the XML to JSON Converter
Why are some keys prefixed with @_?
Those are XML attributes. The prefix keeps them apart from child elements that may have the same name. The JSON to XML Converter turns them back into attributes.
Why is one element an array and another an object?
An element that appears several times under the same parent becomes an array. An element that appears only once stays a single object. If your code always expects an array, check for this case.
What if my XML is invalid?
Conversion stops with an error. Use Check & Suggest Fix or the XML Validator to find unclosed tags, unquoted attributes or a missing root element.