How to Convert XML to JSON: Complete Guide
Last updated: 2026-04-14
XML has been the backbone of enterprise data exchange for decades — SOAP APIs, RSS feeds, configuration files, and government data exports all rely on it. But modern web applications overwhelmingly prefer JSON. When you receive an XML payload and need to work with it in JavaScript, Python, or any language with native JSON support, conversion is the fastest path forward.
Step-by-Step: Convert XML to JSON with Convertee
- Open Convertee and select XML as the source format and JSON as the target.
- Paste your XML document into the input panel, or drag-and-drop an
.xmlfile. - Review the conversion options — attribute handling, text node key naming, and array detection.
- Press Convert (Cmd+Enter).
- Copy the resulting JSON or download it as a
.jsonfile.
Convertee processes your XML entirely in the browser. Nothing is sent to a remote server — your data stays on your machine.
Understanding the Formats
XML
XML (Extensible Markup Language), defined by the W3C XML 1.0 specification, uses nested elements with opening and closing tags to represent hierarchical data. Elements can carry attributes, namespaces, and mixed content (text interleaved with child elements). While expressive, this complexity makes XML verbose compared to JSON.
JSON
JSON (RFC 8259) maps data to objects, arrays, strings, numbers, booleans, and null. It has no concept of attributes or namespaces, so the conversion process must decide how to represent those XML-specific features. Common conventions include prefixing attribute keys with @ and storing text content under a #text key.
Before / After Example
Input XML:
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price>5.95</price>
</book>
</catalog>Output JSON:
{
"catalog": {
"book": [
{
"@id": "bk101",
"author": "Gambardella, Matthew",
"title": "XML Developer's Guide",
"price": "44.95"
},
{
"@id": "bk102",
"author": "Ralls, Kim",
"title": "Midnight Rain",
"price": "5.95"
}
]
}
}Common Use Cases
- Consuming SOAP APIs. Legacy enterprise services return XML responses. Converting to JSON lets you parse the data with standard JavaScript methods instead of wrestling with DOM traversal or XPath queries.
- Processing RSS/Atom feeds. Blog aggregators and news readers often ingest RSS (XML) feeds. Converting to JSON simplifies storage in document databases like MongoDB or Firebase Firestore.
- Migrating configuration files. Java and .NET applications frequently use XML config files. When refactoring to a Node.js stack, converting those configs to JSON eliminates the need for XML parsing libraries.
- Government and healthcare data. Standards like HL7 CDA (Clinical Document Architecture) and Open311 use XML. Analysts who need this data in a frontend dashboard convert it to JSON for charting libraries.
Options and Configuration
| Option | Default | What It Does |
|---|---|---|
| Attribute prefix | @ | Prefix added to XML attribute names in the JSON output (e.g., an attribute id becomes @id). |
| Text node key | #text | Key used for text content when an element has both attributes and text. |
| Force arrays | Off | When enabled, single child elements are always wrapped in an array for consistent structure. |
| JSON indent | 2 spaces | Controls the indentation of the JSON output. Choose 2 or 4 spaces, tabs, or minified. |
Frequently Asked Questions
- How does Convertee handle XML attributes?
- By default, XML attributes are prefixed with '@' in the JSON output. For example, <book id="101"> becomes { "@id": "101" }. You can change the prefix character in the options.
- What happens with XML namespaces?
- Namespace prefixes are preserved as part of the element name in the JSON output. For example, <ns:element> becomes a key named 'ns:element'. Full namespace URI resolution is not performed.
- Can I convert XML with mixed content (text and child elements)?
- Yes. When an element contains both text and child elements, the text content is stored under a '#text' key alongside the child elements in the JSON object.
- Is my XML data sent to a server?
- No. Convertee parses and converts your XML entirely in the browser using JavaScript. Your data never leaves your machine.