XML to JSON Converter

The XML to JSON Converter transforms any well-formed XML document into a valid JSON structure, mapping elements to keys, attributes to @-prefixed keys, and repeated siblings to arrays. Use it when consuming SOAP APIs, processing legacy XML data exports, or converting RSS and Atom feeds before working with them in modern JavaScript or Python applications.

S. Siddiqui

Edited by

S. SiddiquiFounder & Editor-in-Chief
Sources:MDN Web DocsW3CIETFUpdated Jun 2026

What Is the XML to JSON Converter?

XML (Extensible Markup Language) and JSON (JavaScript Object Notation) are two of the most widely used data interchange formats in software development. XML was the dominant standard throughout the 2000s, powering everything from RSS feeds and SOAP web services to Microsoft Office documents, government data portals, and financial messaging formats such as FIXML and FpML. JSON became the preferred format for REST APIs from the 2010s onward because it is lighter, natively parseable in JavaScript, and significantly easier to work with in modern programming languages.

The XML to JSON Converter takes a valid XML document and maps each element, attribute, and text node to a corresponding JSON structure. Root elements become the top-level JSON object, child elements become nested keys, and repeated sibling elements of the same name are automatically grouped into JSON arrays. XML attributes are represented using the @ prefix convention — so an element <order id="1234"> produces {"@id": "1234"} in the JSON output. Text content within an element that also carries attributes is mapped to a #text key.

The tool follows the IETF RFC 8259 JSON specification and the W3C XML standard to produce output that is valid and predictable. It handles XML namespaces, CDATA sections, self-closing tags, and deeply nested hierarchies without any manual configuration.

Teams working with legacy enterprise systems, government open data feeds, financial message formats, healthcare HL7 or FHIR XML payloads, or publishing workflows based on DITA or DocBook regularly need to transform XML into JSON before feeding data into a modern API, NoSQL database, or front-end application. This tool removes the need to write a one-off parsing script every time the task arises.

How to Use the XML to JSON Converter

  1. Paste your XML into the input panel. The tool accepts any well-formed XML document, including documents with namespaces, attributes, nested elements of any depth, CDATA sections, and XML processing instructions.
  2. Click Convert to JSON. The conversion runs instantly in your browser. The JSON output appears in the right panel, indented with two-space formatting for readability.
  3. Review the output structure. XML attributes appear under keys prefixed with @ — for example, an attribute named type becomes "@type" in the JSON. Text content of elements that also have attributes or child elements appears under the #text key. If your target system expects a different structure, note which keys need renaming.
  4. Check array handling. Repeated sibling elements with the same tag name are automatically grouped into a JSON array. If only one such element appears in your XML sample, it will appear as an object, not an array. If your downstream code always expects an array, wrap single objects at the point of consumption.
  5. Copy or download the result. Use the Copy button to paste the JSON directly into your code editor, Postman, or API client. Click Download to save as a .json file.
  6. Validate if needed. For critical integrations, paste the output into a JSON Validator to confirm the output is syntactically correct before using it in production.

Why Use This Tool

Writing an XML-to-JSON parser by hand is time-consuming and error-prone. Edge cases accumulate quickly: self-closing tags, mixed content nodes, XML namespaces with colon-prefixed element names, CDATA sections, XML declarations, and the ambiguity of whether a single-item list should produce an object or an array. A single missed case can cause a downstream API call to fail silently or a database insert to reject the record.

Back-end developers consuming XML APIs

Many enterprise and government APIs — including HMRC's Making Tax Digital gateway, Companies House XML feeds, and carrier shipping APIs — still deliver data exclusively in XML. A developer building a modern Node.js, Python, or Go service against these systems needs to convert XML payloads to JSON before working with them programmatically. This tool lets you inspect the exact output structure during development so you can write accurate field mappings before committing to code.

Data engineers transforming legacy exports

Data warehouses and ETL pipelines frequently receive XML exports from ERP systems, legacy CRMs, or mainframe reporting tools. Transforming these files into JSON before loading into BigQuery, Snowflake, or a PostgreSQL JSONB column requires a reliable structural mapping. Using this tool to verify the transformation on a sample record before building the pipeline saves hours of debugging once the full dataset is loaded.

Front-end developers consuming RSS and Atom feeds

RSS 2.0 and Atom feeds are XML-based. A front-end developer building a content aggregator, podcast player, or news widget needs to either parse XML directly in the browser or convert it to JSON first. This tool shows exactly how the XML element hierarchy maps to JSON keys, making it straightforward to write accurate data selectors in React, Vue, or vanilla JavaScript.

QA engineers verifying transformation layers

When a service's XML-to-JSON transformation layer is updated, QA engineers need to verify the output against a known-good reference. This tool produces a canonical JSON output for a given XML input, making it easy to diff the expected structure against what the updated service actually returns without running the full test pipeline each time.

Real-World Use Cases

Back-end developer integrating a logistics carrier's SOAP API

A back-end developer at a UK e-commerce company integrates shipment tracking updates from a carrier whose API exclusively delivers SOAP/XML responses. The internal order management system expects JSON. During development, the developer uses this tool to paste a real XML tracking response and examine the resulting JSON structure — specifically how the carrier uses XML attributes for status codes alongside child elements for timestamps. The tool reveals that the carrier uses @code attributes which map to "@code" keys in the JSON output, allowing the developer to write the correct field extraction logic before writing a single line of transformation code.

Data engineer loading government planning data into PostgreSQL

A data engineer at a proptech startup downloads planning application records from a UK council's open data portal in XML format. The records need to be loaded into a PostgreSQL database using a JSONB column for flexible querying. Using this tool, the engineer pastes a sample record and confirms the exact key names the converter produces for each nested element before writing the import script. This prevents a class of bug where the script assumes one key name but the actual conversion produces a different one — a discrepancy that is only discovered after thousands of rows have been loaded with the wrong structure.

Healthcare developer parsing HL7 FHIR XML payloads

A developer at a healthtech company receives patient resource records from a hospital system in HL7 FHIR XML format. The application's internal data model works with JSON. The FHIR XML schema uses extensive namespace prefixes and deeply nested elements. The developer uses this tool to convert sample records and verify that namespace prefixes are handled correctly and that repeated <coding> elements within a <code> element produce a JSON array rather than being overwritten — a critical structural requirement for preserving all diagnostic codes in the patient record.

Front-end developer building an RSS news aggregator

A front-end developer building a news aggregator in React uses an RSS 2.0 feed from a major UK news publisher. RSS is XML-based, and the developer needs to understand how the <item> elements, their <title>, <link>, <pubDate>, and <description> children, and any namespace-qualified elements like <media:content> map to JSON. After converting a sample feed, the developer can write exact data selectors for the React components with confidence, knowing the JSON keys match the output structure.

Common Mistakes and Troubleshooting

Pasting malformed XML that is not well-formed

The converter requires well-formed XML: every opening tag must have a matching closing tag, attribute values must be enclosed in quotes, there must be exactly one root element, and special characters in text content must be escaped as XML entities (&amp;, &lt;, &gt;). If the converter returns an error or blank output, paste your XML into an XML validator first. Common sources of malformed XML include HTML snippets (which are not valid XML), copy-pasted spreadsheet data, or truncated API responses.

Expecting attributes to appear as plain keys

XML attributes are not the same as child elements. In the JSON output, attributes appear under keys prefixed with @ — so <product id="42" category="books"> produces {"@id": "42", "@category": "books"} rather than {"id": "42", "category": "books"}. If your downstream code expects plain keys without the prefix, rename them after conversion or configure your production parser to strip the prefix.

Repeated elements appearing as objects instead of arrays

If your XML only contains one instance of a repeating element in the sample you paste — for example, a <books> container with a single <book> child — the converter maps that single child to an object, not an array. When the real data has multiple children, the converter produces an array. If your code always expects an array for that key, add a normalisation step: const books = Array.isArray(data.books.book) ? data.books.book : [data.books.book];

Misunderstanding the #text key

The #text key appears when an element has both a text node and at least one attribute or child element. For example, <name type="full">Alice Smith</name> produces {"@type": "full", "#text": "Alice Smith"}. If an element has only text content and no attributes or children, it produces a plain string value. The #text convention is standard across most XML-to-JSON converters and is not an error — your consuming code simply needs to read from #text for the text value.

Namespace prefixes creating unexpected key names

XML elements qualified with a namespace prefix — such as <ns0:order>, <soap:Body>, or <media:content> — appear in the JSON output with the prefix included as part of the key name. If your downstream system expects plain key names without namespace prefixes, add a post-processing step to strip or replace the prefix. Alternatively, if you control the XML source, use a namespace-free format where possible.

Losing CDATA content

CDATA sections (<![CDATA[...]]>) are treated as plain text in the JSON output — the CDATA wrapper is stripped and the raw text content is preserved. This is correct behaviour. If the CDATA section contains HTML or embedded XML, that inner content will appear as a plain text string in the JSON, not as a parsed structure. If you need to parse the inner content, process it separately after extraction.

Last reviewed: June 7, 2026

Frequently Asked Questions

Can I convert any XML file to JSON?
You can convert any well-formed XML file to JSON. The XML must have a single root element, matching opening and closing tags, and properly quoted attribute values. Documents that are valid HTML but not valid XML (such as HTML5 pages) may not convert cleanly without preprocessing. Some XML features — such as XML Schema definitions, DTD declarations, and processing instructions — have no direct JSON equivalent and are typically stripped during conversion.
How are XML attributes represented in the JSON output?
XML attributes are mapped to JSON keys prefixed with the @ symbol. For example, <order id="1234" status="shipped"> produces {"@id": "1234", "@status": "shipped"} in the JSON output. This is the most widely used convention across XML-to-JSON libraries including xmltodict (Python), xml2js (Node.js), and Jackson (Java). If your downstream system expects plain keys without the prefix, rename them in a post-processing step.
Why does my converted JSON have a #text key?
The #text key appears when an XML element has both text content and at least one attribute or child element. For example, <name type="full">Alice Smith</name> produces {"@type": "full", "#text": "Alice Smith"} because the converter needs to store both the attribute and the text content. Elements with only text content and no attributes produce a plain string value without the #text wrapper. Read from ."#text" in your consuming code to access the text value.
What happens if the same XML element name appears multiple times?
Repeated sibling elements with the same tag name are automatically grouped into a JSON array. For example, a <books> element containing three <book> children produces {"books": {"book": [{...}, {...}, {...}]}}. If only one such element exists in your input, it produces an object instead of an array — a common inconsistency to handle in consuming code with a check like: Array.isArray(data.books.book) ? data.books.book : [data.books.book].
How do I convert XML to JSON in Python?
The most widely used Python library is xmltodict. Install it with pip install xmltodict, then: import xmltodict, json; with open('data.xml') as f: data = xmltodict.parse(f.read()); print(json.dumps(data, indent=2)). xmltodict follows the same @attribute and #text conventions as this tool. For large files, use xmltodict.parse() with a streaming callback. The built-in xml.etree.ElementTree module also works but requires more manual mapping code.
How do I convert XML to JSON in JavaScript?
In Node.js, the most popular library is xml2js. Install it with npm install xml2js, then: const xml2js = require('xml2js'); xml2js.parseString(xmlString, (err, result) => { console.log(JSON.stringify(result, null, 2)); }). In the browser, DOMParser can parse XML and you can traverse the resulting DOM tree manually. For a zero-dependency approach in modern environments, the browser's built-in DOMParser combined with a recursive traversal function is a clean alternative.
What is the difference between XML and JSON?
XML is a markup language that represents data as a tree of elements and attributes with explicit opening and closing tags. JSON represents data as key-value pairs, arrays, and primitive types using a compact notation. XML supports namespaces, schemas (XSD), stylesheets (XSLT), and comments natively. JSON does not support any of these but is simpler, smaller in payload size for equivalent data, and natively parseable in JavaScript. JSON has become the default for REST APIs; XML remains prevalent in enterprise integration, document publishing, and legacy SOAP services.
Why is JSON preferred over XML for modern REST APIs?
JSON is preferred for REST APIs because it is natively supported in JavaScript without parsing overhead, its syntax is more compact (30–50% smaller for equivalent data structures), it maps directly to objects and arrays in most programming languages, and it is easier for humans to read and write. XML's advantages — namespaces, schema validation, and XSLT transformation — are valuable in enterprise integration scenarios but are unnecessary overhead for most web API use cases.
How are XML namespaces handled in the JSON output?
XML namespace prefixes are preserved in the JSON key names. An element <soap:Body> becomes the key "soap:Body" and an attribute xmlns:ns="http://example.com" becomes "@xmlns:ns". If your downstream system expects keys without namespace prefixes, add a post-processing step to rename or strip the prefix. Most production XML-to-JSON libraries offer namespace handling options — xml2js in Node.js supports explicitCharkey and ignoreAttrs options to control this behaviour.
Is there a size limit for XML I can convert with this tool?
This tool runs entirely in your browser and processes your XML locally without sending data to any server. The practical limit is the memory available to your browser tab. Most XML documents up to several megabytes convert without difficulty. For very large XML files (tens of megabytes or multi-gigabyte data exports), use a command-line tool or library: python3 -c "import xmltodict,json,sys; print(json.dumps(xmltodict.parse(sys.stdin.read()), indent=2))" is a one-liner that handles large files efficiently.

Rate This Tool

Was this tool helpful?

Be the first to rate this tool

About the Author

S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief

LinkedIn Profile

S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.

View full profile

Authoritative Sources

Formulas and data in this tool are based on guidelines from the above sources.