DevTools Logo

XML to JSON Converter

XML to JSON Converter

Convert XML documents to JSON with attribute handling and configurable parsing options

Input & Settings

2 spaces

About this tool

This tool converts XML documents into JSON objects using a robust client-side parser. It preserves element nesting, handles attributes (prefixed by default with @_), parses numbers and booleans, and trims whitespace. Use it to bridge XML-based APIs, config files, or legacy data into modern JSON workflows — all processing happens locally in your browser, nothing is uploaded.

Examples & Use Cases

Simple XML to JSON

<!-- XML Input -->
<person>
  <name>John Doe</name>
  <age>30</age>
  <active>true</active>
</person>

// JSON Output
{
  "person": {
    "name": "John Doe",
    "age": 30,
    "active": true
  }
}

A basic XML element with text content is converted to a nested JSON object. Numeric and boolean values are parsed automatically.

XML with Attributes

<!-- XML Input -->
<book id="123" category="fiction">
  <title lang="en">The Great Gatsby</title>
  <year>1925</year>
</book>

// JSON Output
{
  "book": {
    "@_id": 123,
    "@_category": "fiction",
    "title": {
      "@_lang": "en",
      "#text": "The Great Gatsby"
    },
    "year": 1925
  }
}

Attributes are prefixed with @_ by default so they never collide with child element names. Text alongside attributes is nested under #text.

Repeated Elements Become Arrays

<!-- XML Input -->
<library>
  <book><title>Book 1</title></book>
  <book><title>Book 2</title></book>
</library>

// JSON Output
{
  "library": {
    "book": [
      { "title": "Book 1" },
      { "title": "Book 2" }
    ]
  }
}

Sibling elements with the same tag name are automatically grouped into a JSON array — the natural representation for repeated XML elements.