XML to JSON Converter

Convert XML to JSON instantly — paste, convert, and copy your data.

Input XML
Output JSON
Converted JSON will appear here...
info

About XML to JSON Converter

XML to JSON Converter translates the tree structure of an XML document into an equivalent JSON object, preserving every attribute, child element, and text node. The root element becomes the top-level key, child elements become nested objects, and any XML attributes appear as properties prefixed with @_ so they cannot be confused with child elements. When the same tag name appears more than once inside a parent, the tool automatically promotes those entries to a JSON array — no manual cleanup required.

The converter is built for integration work: consuming a SOAP or RSS feed in a JavaScript application that expects JSON, preparing XML configuration exports for a NoSQL import, or inspecting the structure of a legacy enterprise payload before writing a mapping layer. Unlike a JSON formatter (which only re-indents existing JSON) or an XML formatter (which only pretty-prints XML), this tool actually changes the data format — the output is valid JSON that any JSON parser can read.

Every conversion runs entirely inside your browser via the native DOMParser API. Your XML is never uploaded, logged, or transmitted to any server, so internal configuration files, API responses with credentials, and proprietary data schemas stay completely private on your own machine. There are no file-size limits, no accounts, and no cost.

star

Key Features

check_circle

Attribute-aware mapping

XML attributes are preserved as @_-prefixed keys in the JSON output, keeping them distinct from child element keys and making the mapping unambiguous.

check_circle

Automatic array promotion

When the same element tag appears more than once under a parent, the tool groups those entries into a JSON array automatically — no manual post-processing needed.

check_circle

CDATA and mixed-content support

CDATA sections are captured under a #cdata key and text nodes alongside child elements are stored as #text, so no content from the original XML is silently dropped.

check_circle

Configurable indentation

Choose 2, 4, 6, or 8 spaces for the JSON output, or switch to compact (minified) mode when you need a single-line payload for an API request or a storage field.

check_circle

100% client-side — no uploads

Conversion runs in the browser using the native DOMParser. Your XML never leaves your device, making it safe for credentials, internal schemas, and proprietary configuration files.

check_circle

Instant error reporting

If the XML is malformed, the parser surfaces the exact error message rather than producing silently broken JSON, so you can fix the source document before using the output.

help

How to Use

01

Paste XML

Copy your XML code and paste it into the left input pane.

02

Convert

Click "Convert" to transform your XML into a JSON object.

03

Copy Result

Use the copy button to grab your JSON output.

code_blocks

Example

A product catalog entry with attributes and repeated child elements. Attributes become @_-prefixed keys; the two tag elements are automatically grouped into a JSON array.

XML input
<product id="P42" currency="USD">
  <name>Wireless Headphones</name>
  <price>89.99</price>
  <tag>audio</tag>
  <tag>wireless</tag>
</product>
JSON output
{
    "product": {
        "@_id": "P42",
        "@_currency": "USD",
        "name": "Wireless Headphones",
        "price": "89.99",
        "tag": [
            "audio",
            "wireless"
        ]
    }
}
lightbulb

Common Use Cases

  • arrow_circle_right

    Consuming SOAP or RSS feeds in a JS app

    Many enterprise APIs and feed formats still return XML. Convert the response to JSON once so your JavaScript code can use standard dot-notation and array methods instead of DOM traversal.

  • arrow_circle_right

    Preparing XML exports for NoSQL ingestion

    Document databases like MongoDB and Firestore expect JSON. Convert an XML data export to JSON as the first step in a migration pipeline before loading it into the database.

  • arrow_circle_right

    Inspecting legacy API payloads

    When you receive an unfamiliar XML payload and need to understand its structure, converting it to JSON makes the hierarchy immediately readable in any JSON viewer or browser console.

  • arrow_circle_right

    Writing field-mapping code between formats

    Before coding a transformation layer between an XML source and a JSON target, use this tool to see exactly how attributes, repeated elements, and text nodes map so you can write accurate selectors from the start.

  • arrow_circle_right

    Verifying XML-to-JSON library output

    When evaluating a parsing library in your codebase, paste the same XML here to get a reference output and compare it with what your library produces — quickly spot attribute handling or array-promotion differences.

quiz

Frequently Asked Questions

What is XML to JSON Converter? expand_more
XML to JSON Converter is a free online tool that transforms XML markup into equivalent JSON data structures. It parses your XML document and produces a clean, well-structured JSON object that preserves the hierarchy, attributes, and text content of the original XML.
How are XML attributes handled? expand_more
XML attributes are converted to JSON properties prefixed with @_ to distinguish them from child elements. For example, an attribute id="123" on an element becomes "@_id": "123" in the JSON output.
Is my data secure? expand_more
Yes. All conversion happens entirely in your browser using JavaScript and the native DOMParser API. No data is transmitted to any server, so your XML content remains completely private.
Does it handle nested XML? expand_more
Yes. The converter uses a recursive algorithm that traverses the entire XML DOM tree, preserving all levels of nesting in the resulting JSON structure.
What happens with repeated elements? expand_more
When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array. For example, multiple <item> elements inside a parent will become an array of objects under the "item" key.
How is this different from the XML Formatter tool? expand_more
The XML Formatter only re-indents and pretty-prints your XML — the output is still XML. This converter actually changes the data format, producing a JSON object you can feed directly to a JavaScript application, a REST client, or a JSON-based database. Use the XML Formatter when you want to keep XML but make it readable; use this tool when you need to switch formats entirely.
How does this differ from CSV to JSON? expand_more
CSV to JSON converts tabular data where rows map to array items and columns map to object keys. XML to JSON converts hierarchical, document-style data that can have attributes, deeply nested elements, and mixed content. Choose this tool when your source is XML with nesting or attributes, and CSV to JSON when your source is a flat spreadsheet or comma-delimited export.
What happens to CDATA sections? expand_more
CDATA sections are captured under a #cdata key in the resulting JSON object. If the element has no attributes and no child elements — only a CDATA section — the value collapses to the raw string directly rather than wrapping it in an extra object.
Can I control the indentation of the JSON output? expand_more
Yes. The toolbar above the editor lets you choose 2, 4, 6, or 8 spaces. You can also toggle Compact mode to produce a minified single-line JSON string, which is useful when you need to paste the value into an API request body or a database field.