HomeFormattersDataXML to JSON Converter

XML to JSON Converter

Data

Convert XML to JSON instantly — paste your XML and get a clean, indented JSON representation. Handles attributes and text nodes. Runs entirely in your browser.

Reviewed by the thecalcu.com team · Last updated July 8, 2026

What is a XML→JSON?

An XML to JSON Converter transforms XML markup into a JSON representation of the same data. XML and JSON are both formats for structured data, but JSON has become the dominant format for web APIs, JavaScript applications, and modern NoSQL databases, while XML remains common in enterprise integrations, SOAP services, and legacy systems.

Converting XML to JSON lets you work with XML-source data using the tools and libraries that consume JSON, parsing it with JSON.parse, querying it with jq, inserting it into MongoDB, or passing it to a REST API endpoint.

The converter maps XML elements to JSON objects, text content to string values, and attributes to prefixed keys (e.g. @category by default). When the same element tag appears multiple times under a parent, the converter groups those elements into a JSON array automatically. Leaf elements with no child elements and no attributes are reduced to plain string values rather than {"#text": "..."} objects, keeping the output as clean as possible.

The conversion runs entirely in your browser using the native DOMParser, nothing is uploaded. For formatting XML while keeping it as XML, use the XML Formatter.


Why Use an XML to JSON Converter?

XML is verbose and harder to consume in modern application code than JSON. Manually rewriting an XML response as JSON is tedious and error-prone, especially when elements repeat or have both attributes and text content. An automated converter handles the structural mapping in one step.

It is also useful when working with legacy SOAP APIs or RSS/Atom feeds that return XML and you need to process the data in a JavaScript or Python script that expects JSON.


Who Should Use This Converter?

Backend developers, converting XML responses from SOAP services, EDI systems, or legacy APIs into JSON for use in modern applications.

Data engineers, transforming XML data exports (from ERPs, CRMs, or government data portals) into JSON for loading into document databases or data pipelines.

Frontend developers, consuming RSS or Atom feeds that return XML and need to display the data in a JSON-driven UI.

Students and learners, understanding the structural parallels and differences between XML and JSON data models.

For the reverse conversion, use the JSON Formatter to inspect the JSON output, or the JSON to CSV Converter to further transform it into a spreadsheet.


What Does the XML to JSON Converter Give You?

The output is a JSON object that mirrors the XML element tree. The root element tag becomes the top-level key. Child elements become nested objects or arrays (when the same tag repeats). Attributes appear as keys with the configured prefix. Leaf text content is represented as plain strings.

You can control JSON indent size (2 spaces, 4 spaces, or minified) and the attribute prefix (@, _, or none).


How to use this XML→JSON calculator

  1. Paste your XML into the XML input field. The default shows a bookstore example.
  2. Choose a JSON Indent size, 2 spaces produces readable output for most uses.
  3. Choose an Attribute prefix, @ is the common convention; choose _ or none if your downstream consumer prefers.
  4. The JSON Output appears instantly.
  5. Click Copy to copy the JSON to your clipboard.
  6. Paste into your application, database import tool, or the JSON to CSV Converter for further processing.

Formula & Methodology

The converter uses the browser's native DOMParser with MIME type application/xml to parse the input into a DOM tree, then traverses the tree recursively.

Mapping rules:
- Element with only text content and no attributes → plain string value
- Element with attributes → object where attribute keys are prefixed (e.g. @name)
- Element with both attributes and text → object with attribute keys plus a #text key
- Element with child elements → object with child tags as keys
- Repeated child tags → grouped into an array under that tag name
- Single child tag → plain object (not a one-element array)

Example:
xml <book category="fiction"><title>Gatsby</title></book> json {"book": {"@category": "fiction", "title": "Gatsby"}} 

Frequently Asked Questions

The converter handles standard XML documents with elements, attributes, text content, and nested structures. It supports both complete documents with an XML declaration and bare fragments. CDATA sections and processing instructions are not included in the JSON output, only element content and attributes are converted.
Attributes are included as keys with a configurable prefix. With the default '@' prefix, an element <book category='fiction'> produces a JSON key '@category'. You can switch to an underscore prefix or no prefix at all using the Attribute Prefix option.
When the same tag appears more than once under a parent, the converter groups those elements into a JSON array. For example, two <book> elements inside <bookstore> produce a 'book' key whose value is an array. A single <book> produces a plain object (not a one-element array).
When an element has both child elements and direct text content, the text is captured under the '#text' key to avoid collision with element-child keys. For pure text-content elements (no child elements, no attributes), the value is returned as a plain string rather than an object.
Converting XML to JSON is lossy in some edge cases, XML comments, processing instructions, and namespace prefixes are not preserved. For round-tripping data reliably, use a schema-aware library in your application code rather than this browser tool.
No. The conversion runs entirely in your browser using the browser's native DOMParser. Your XML never leaves your device.
Yes, SOAP envelopes and RSS/Atom feeds are standard XML and will be converted. The resulting JSON will mirror the XML structure, including any namespace prefixes in the element tag names.
2 spaces produces compact output that is easy to read. 4 spaces is more spacious and preferred in Python-style projects. Minified removes all whitespace, use it when passing the JSON to another tool programmatically and readability is not needed.
The [XML Formatter](/xml-formatter/) pretty-prints XML, keeping it as XML with consistent indentation. This tool converts XML into a different format (JSON), which is more suitable for JavaScript applications, REST APIs, and NoSQL databases.
If the resulting JSON is an array of objects (which often happens after unwrapping one level of nesting), you can paste it into the [JSON to CSV Converter](/json-to-csv-formatter/) to produce a spreadsheet-ready CSV.
The converter uses the browser's native XML parser, which returns a parsererror element for invalid XML. The tool detects this and shows the parser's error message as output, for example 'XML parse error: mismatched tag', so you can identify and fix the issue.
Also known as
xml to json converterconvert xml to jsonparse xml to jsonxml json transformxml to object