DataFormattools
XML · Converter

XML to JSON Converter

Convert XML to JSON online. Transform XML elements, attributes, and CDATA into structured JSON objects with fast in-browser execution.

Interactive Editor
XML Input
0 lines · 0 B
1
Auto-executes on edit
JSON Output
0 lines · 0 B
1
100% In-Browser Privacy: All conversions, formatting, and validations run purely on your machine using client-side JavaScript. Your data, code snippets, and environment variables are never transmitted to any server or recorded in logs.
Specifications

How XML → JSON Works

  • Uses fast-xml-parser to construct JavaScript objects from XML.
  • Converts XML attributes into @_ prefixed properties.
  • Transforms repeating XML tags into JSON arrays.
Demonstration

Example Input & Output

Parses XML elements and attributes into a structured JSON hierarchy, converting numeric and boolean strings into native JSON types.

XML Input
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <book category="fiction">
    <title>The Great Gatsby</title>
    <author>F. Scott Fitzgerald</author>
    <year>1925</year>
    <price>10.99</price>
  </book>
</bookstore>
JSON Output
{
  "bookstore": {
    "book": {
      "@_category": "fiction",
      "title": "The Great Gatsby",
      "author": "F. Scott Fitzgerald",
      "year": 1925,
      "price": 10.99
    }
  }
}
Applications

Common Use Cases

Modernizing Legacy APIs

Convert legacy XML SOAP service responses into JSON for frontend consumption.

Data Migration

Ingest XML exports into MongoDB or PostgreSQL JSONB databases.

Guidelines

Key Specifications & Gotchas

Single Item Arrays

A single XML element with repeating sibling potential may parse as an object rather than an array unless configured.

Questions

Frequently Asked Questions

How are XML attributes converted to JSON?

Attributes are mapped to prefixed properties (e.g. @_category) within the corresponding object.

How are repeating XML elements handled?

Repeating tags with identical names are grouped into JSON arrays.

Related XML & Data Format Tools

View all 41 tools →