XML to JSON
Convert XML to JSON online, keeping attributes and turning repeated elements into arrays. Malformed XML is reported with its location.
Runs in your browser · Nothing uploadedFree · No sign-up
Something not working, or missing a feature? Send feedback
About the XML to JSON
The XML to JSON converter turns XML documents, feeds and SOAP responses into JSON you can use in JavaScript. Attributes are preserved and repeated elements become arrays.
Conversion happens in your browser, so your files and records stay private.
How to use the XML to JSON
- Paste XML or open a file.
- Choose the indentation.
- Copy or download the JSON.
Example
Input
<catalog>
<product id="1" featured="true">
<name>Notebook</name>
<price currency="EUR">4.50</price>
</product>
<product id="2">
<name>Pen</name>
<price currency="EUR">1.20</price>
</product>
</catalog>Result
{
"catalog": {
"product": [
{
"name": "Notebook",
"price": {
"#text": 4.5,
"@_currency": "EUR"
},
"@_id": "1",
"@_featured": "true"
},
{
"name": "Pen",
"price": {
"#text": 1.2,
"@_currency": "EUR"
},
"@_id": "2"
}
]
}
}Repeated <product> elements become an array, attributes become @_ keys, and an element with both an attribute and text keeps the text in #text. Numeric text becomes a number (4.50 → 4.5); attribute values stay strings.
Common mistakes
- Arrays that are sometimes objects. A list with one <product> becomes an object, and with two an array. Code that reads the result should handle both, or always wrap the value in an array.
- Namespace prefixes. Prefixed names such as soap:Envelope keep their prefix as part of the key. Use the full key, including the prefix, in your code.
- Number formatting. Element text that looks like a number is converted, so 4.50 becomes 4.5 and trailing zeros are lost. Codes with leading zeros, such as 00123, and hex text stay strings.
Works well with the XML to JSON
- JSON Viewer: explore the converted feed as a tree.
- JSON to TypeScript: generate types for the converted data.
- XML Validator: find the error when the XML does not convert.
Frequently asked questions
How are attributes represented?
Attributes become keys starting with @_ (for example @_id), next to the child elements, so no information is lost.
Why is a single child not an array?
Elements that appear once become objects; elements that repeat become arrays. Check the sample to see both.
Are comments kept?
No. JSON has no comments, so XML comments are dropped.
Can it convert SOAP responses?
Yes. The envelope and body become nested objects; navigate to the body element to reach the payload.
Guides and tutorials
Related tools
JSON to CSV
Convert JSON arrays to CSV online with automatic column detection, nested object flattening and custom delimiters. Open the result in Excel or Sheets.
CSV to JSON
Convert CSV to a JSON array online with header detection, type inference and delimiter auto-detection. Turn spreadsheet exports into data for APIs and code.
JSON to XML
Convert JSON to well-formed XML online with a configurable root element and attribute support. Validate the input and download the XML file.
JSON to YAML
Convert JSON to clean, human-readable YAML online. Turn API responses and package files into config for Kubernetes, Docker Compose or CI pipelines.
YAML to JSON
Convert YAML documents to formatted JSON online with syntax validation. Errors are reported by line, so broken indentation is quick to find and fix.
JSON to PHP Array
Convert JSON to a PHP array literal online, using short [] or long array() syntax. Paste API responses straight into PHP code, tests and config files.