How to Convert XML to JSON
Published 2026-08-10
4 min read
By CoShareX
XML (Extensible Markup Language) is a common data format in enterprise integrations and SOAP APIs. However, modern JavaScript-based web applications prefer working with JSON. Converting XML structures to JSON objects simplifies parsing and data manipulation.
In this guide, we'll explain how to parse XML markup and convert it to structured JSON objects.
Structural Nodes Mapping
When converting XML to JSON:
- Nested markup nodes are translated to nested JSON object properties.
- XML element text values are mapped to string properties.
- Element attributes are typically prefixed with
@in the resulting JSON keys.
Input XML:
xml
1
2
3
<product sku="A101">
<title>Developer Keyboard</title>
</product>Output JSON:
json
1
2
3
4
5
6
{
"product": {
"@sku": "A101",
"title": "Developer Keyboard"
}
}Featured Tool
XML to JSON
Convert structured XML tag configurations into JSON object models.
Sibling Elements to Arrays
If the input XML has multiple sibling tags with the same name, standard XML parsers group them into a single JSON array under that tag name. For example, multiple <role> tags will convert to a single "role": [...] array in the JSON output.