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.
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
- 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.
- 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.
- Review the output structure. XML attributes appear under keys prefixed with
@— for example, an attribute namedtypebecomes"@type"in the JSON. Text content of elements that also have attributes or child elements appears under the#textkey. If your target system expects a different structure, note which keys need renaming. - 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.
- 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
.jsonfile. - 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 (&, <, >). 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.
Frequently Asked Questions
Can I convert any XML file to JSON?
How are XML attributes represented in the JSON output?
Why does my converted JSON have a #text key?
What happens if the same XML element name appears multiple times?
How do I convert XML to JSON in Python?
How do I convert XML to JSON in JavaScript?
What is the difference between XML and JSON?
Why is JSON preferred over XML for modern REST APIs?
How are XML namespaces handled in the JSON output?
Is there a size limit for XML I can convert with this tool?
Rate This Tool
Was this tool helpful?
Be the first to rate this tool
About the Author
S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.
View full profileAuthoritative Sources
Formulas and data in this tool are based on guidelines from the above sources.