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.
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.
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"}}