XML to JSON Converter — Free Online Tool
Converting XML documents to JSON is one of the most common data transformation tasks in modern API development. Our free XML to JSON converter handles the full range of XML structures — nested elements, attributes, text nodes, and repeated elements — and converts them into clean, readable JSON instantly in your browser.
What Is XML to JSON Conversion?
XML (eXtensible Markup Language) was the dominant data exchange format for enterprise systems throughout the 2000s and is still deeply embedded in SOAP services, RSS/Atom feeds, Android configuration, Maven/Gradle build files, Microsoft Office file formats, SVG, and legacy integration layers. JSON (JavaScript Object Notation) is the standard for REST APIs, web frontends, Node.js services, mobile apps, and modern data pipelines.
Converting XML to JSON is required when:
- Consuming a SOAP or legacy XML API and needing to work with the data in JavaScript or Python
- Parsing RSS/Atom feeds for content aggregation or display
- Migrating from an XML-based config system (like Spring XML beans) to a JSON-based one
- Processing Android resource exports or other XML-heavy tool outputs
- Extracting data from XML reports exported by ERPs (SAP, Oracle, etc.)
- Working with XLIFF or TMX translation files in localization pipelines
How to Use the XML to JSON Converter
- Paste your XML — including the XML declaration if present — into the input textarea
- Click Convert to JSON
- The JSON output appears instantly, properly pretty-printed with 2-space indentation
- Click Copy to grab the JSON for use in your code
All processing happens locally in your browser. Your XML data is never transmitted.
Example
XML Input:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<book id="bk101">
<title>The Pragmatic Programmer</title>
<author>Andrew Hunt</author>
<price>49.99</price>
<inStock>true</inStock>
</book>
<book id="bk102">
<title>Clean Code</title>
<author>Robert C. Martin</author>
<price>39.99</price>
<inStock>false</inStock>
</book>
</catalog>
JSON Output:
{
"catalog": {
"book": [
{
"@attributes": { "id": "bk101" },
"title": "The Pragmatic Programmer",
"author": "Andrew Hunt",
"price": "49.99",
"inStock": "true"
},
{
"@attributes": { "id": "bk102" },
"title": "Clean Code",
"author": "Robert C. Martin",
"price": "39.99",
"inStock": "false"
}
]
}
}
How XML Structures Map to JSON
| XML Structure | JSON Representation |
|---|---|
<element>text</element> | "element": "text" |
<element attr="value"> | "element": { "@attributes": { "attr": "value" } } |
Repeated <item> elements | "item": [...] (converted to array) |
| Nested elements | Nested JSON objects |
<empty/> | "empty": {} |
| Mixed text and child elements | "element": { "#text": "...", "child": "..." } |
XML Attributes in JSON
XML attributes pose a conversion challenge because JSON has no native concept of attributes. Our converter preserves attributes under a special @attributes property:
XML: <user id="42" role="admin">Alice</user>
JSON: { "user": { "@attributes": { "id": "42", "role": "admin" }, "#text": "Alice" } }
This is the most common convention used by XML-to-JSON libraries across many languages (Python’s xmltodict, PHP’s simplexml_decode, etc.).
Repeated Elements Become Arrays
One of the most important conversion rules: when the same XML element name appears more than once within a parent, our converter automatically wraps them in a JSON array. This is crucial for correctly representing XML lists:
<fruits>
<fruit>Apple</fruit>
<fruit>Banana</fruit>
<fruit>Cherry</fruit>
</fruits>
Becomes: { "fruits": { "fruit": ["Apple", "Banana", "Cherry"] } }
Frequently Asked Questions
Does this tool handle XML namespaces?
The converter processes the XML structure using the browser’s native DOMParser. Namespace prefixes (e.g., soap:Body, xsi:type) are preserved as-is in the JSON output as part of the element name. Full namespace resolution (mapping prefixes to URIs) is not performed.
What happens to the XML declaration <?xml ... ?>?
The XML declaration is ignored. It is a processing instruction, not part of the document tree. The conversion starts from the root document element.
Can I convert very large XML documents?
Yes. The conversion runs in your browser’s JavaScript engine. Very large documents (several megabytes) may take a moment to process. There is no server-side size limit.
Is all text in JSON converted to strings?
Yes. XML has no native numeric or boolean types — all content is text. When converted to JSON, all text values become JSON strings, even if they look like numbers or booleans. You will need to cast types in your application code after conversion.
Does the parser handle CDATA sections?
The browser’s DOMParser handles CDATA sections by converting them to text nodes. The content of <![CDATA[...]]> will appear as a regular text value in the JSON output.
What is the #text property in the JSON output?
When an XML element has both attributes and text content, the text content is stored under a #text key in the JSON object: { "@attributes": {...}, "#text": "text content" }. This is a common convention to handle the ambiguity in XML’s mixed-content model.
Will the converter work with SVG files?
SVG is valid XML. You can paste SVG markup into this tool and receive a JSON representation of the SVG document tree. However, for most SVG use cases (rendering, animation), you’d work with the SVG directly rather than converting it to JSON.