Skip to main content

Free XML to JSON Converter Convert XML documents to JSON with automatic array detection for repeated elements.

XML to JSON illustration
🔄

XML to JSON

Convert XML documents to JSON with automatic array detection for repeated elements.

1

Paste XML

Paste your XML document into the input area.

2

Review JSON Output

The JSON output preserves the XML structure with automatic array detection.

3

Copy JSON Output

Copy the formatted JSON output for use in your applications.

Loading tool...

What Is XML to JSON?

XML to JSON converts Extensible Markup Language documents into JavaScript Object Notation format. This converter uses the browser's native DOMParser for reliable, standards-compliant XML parsing and transforms the resulting DOM tree into JSON. Repeated sibling elements with the same tag name are automatically grouped into arrays. Leaf elements (those with only text content and no children) have their text extracted as string values. The root element becomes the top-level JSON key, preserving the document structure.

Why Use XML to JSON?

  • Uses browser-native DOMParser for reliable, standards-compliant XML parsing.
  • Automatic detection and grouping of repeated elements into JSON arrays.
  • Preserves nested XML structure in the JSON output.
  • Handles well-formed XML of any complexity level.

Common Use Cases

API Migration

Convert XML API responses to JSON for modern REST/GraphQL API development.

Data Processing

Transform XML data into JSON for processing with JavaScript applications.

Configuration Migration

Convert XML configuration files to JSON format for modern applications.

Web Scraping

Transform scraped XML/HTML data into JSON for analysis and storage.

Technical Guide

The converter uses a recursive algorithm to traverse the XML DOM tree. For each element, it checks whether the element has child elements or only text content. Text-only elements return their text content as a string value.

For elements with children, a JavaScript object is created with child tag names as keys. When multiple children share the same tag name, they are automatically grouped into a JSON array. This heuristic works well for most XML data structures.

The root element's tag name becomes the top-level key in the JSON output, ensuring the root element name is preserved. Text content is extracted using the textContent property, which concatenates all descendant text nodes.

Note: XML attributes are not currently preserved in the JSON output. Only element names and text content are converted. For attribute-heavy XML, consider using a dedicated XML-to-JSON library with attribute mapping options.

Tips & Best Practices

  • 1
    Repeated XML elements with the same tag name are automatically grouped into JSON arrays.
  • 2
    XML attributes are not included — only element names and text content are converted.
  • 3
    The root element tag name becomes the top-level JSON key.
  • 4
    Ensure your XML is well-formed — malformed XML will produce an error message.

Related Tools

Frequently Asked Questions

Q Are XML attributes preserved?
Currently, only elements and text content are converted. Attributes are not included in the JSON output.
Q How are repeated elements handled?
Elements with the same tag name under the same parent are automatically grouped into a JSON array.
Q What about XML namespaces?
Namespace prefixes appear in the JSON key names. The namespace URI is not separately represented.
Q Can it handle CDATA sections?
Yes, CDATA content is included in the text content of the parent element.
Q What if the XML is malformed?
The browser's DOMParser will report an error, which is displayed to the user.

About This Tool

XML to JSON is a free online tool by FreeToolkit.ai. All processing happens directly in your browser — your data never leaves your device. No registration or installation required.