XML to JSON Converter
DataConvert 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
- Paste your XML into the XML input field. The default shows a bookstore example.
- Choose a JSON Indent size, 2 spaces produces readable output for most uses.
- Choose an Attribute prefix,
@is the common convention; choose_or none if your downstream consumer prefers. - The JSON Output appears instantly.
- Click Copy to copy the JSON to your clipboard.
- Paste into your application, database import tool, or the JSON to CSV Converter for further processing.
Formula & Methodology
The converter uses the browser's nativeDOMParserwith MIME typeapplication/xmlto 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#textkey - 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