XML to JSON Converter

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

Input & Settings

2 spaces

JSON Output

Converted JSON will appear here

Analysis & Stats

Conversion statistics will appear here

XML
Markup, verbose, attributes
JSON
Lightweight, native to JS/REST

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.

    Examples

    Convert a simple XML document

    Input
    <config>
      <database host="localhost" port="5432" />
      <debug>true</debug>
    </config>
    Output
    {
      "config": {
        "database": {
          "@_host": "localhost",
          "@_port": "5432"
        },
        "debug": true
      }
    }

    With default settings, XML attributes get an @_ prefix and the text node becomes the property value. Boolean strings are parsed to true.

    Disable attribute prefix and number parsing

    Input
    <item id="42" price="9.99">Book</item>
    Output
    {
      "item": {
        "@_id": "42",
        "@_price": "9.99",
        "#text": "Book"
      }
    }

    With parseAttributeValue false, id and price stay as strings even if they look numeric. The element's text node is available as #text when textNodeName is set.

    About this tool

    XML to JSON Converter transforms a well-formed XML document into its equivalent JSON representation entirely in your browser. It uses fast-xml-parser to parse and rebuild the document, and XMLValidator to check well-formedness before attempting conversion.

    Configurable options let you control how attributes, text nodes, number parsing, boolean parsing, whitespace trimming, and output indentation are handled, so the output matches the schema your application expects.

    Everything runs client-side — no XML is uploaded to any server.

    How to use

    1. Paste or load XML

      Paste your XML into the input area, load a sample, or upload an .xml or .txt file.

    2. Check well-formedness

      The tool validates the XML with XMLValidator first. If the input has mismatched tags or other syntax errors, it reports the error with a line number instead of producing output.

    3. Adjust conversion options

      Toggle attribute prefix (default @_), number parsing, boolean parsing, whitespace trimming, and the indent size (1–8 spaces).

    4. Copy or download the JSON

      Copy the formatted JSON output or download it as a .json file.

    Use cases

    Migrating XML config to JSON

    Turn a legacy XML configuration into a JSON file your modern application can read without rewriting it by hand.

    Debugging XML API responses

    Paste a raw XML response from a SOAP or legacy REST endpoint and read it as structured JSON instead of scanning tags.

    Preparing test fixtures

    Convert XML-formatted test data into JSON fixtures for tools like Jest or testing libraries that consume JSON.

    Common mistakes

    Mistake:Forgetting that text-only elements become the property value directly.

    Fix:An element with no children but only text, like <name>Ada</name>, becomes { "name": "Ada" }. Mixed content (text and child elements) puts the text in the configured textNodeName key.

    Mistake:Not checking whether the parser is in cdataTagName mode when CDATA sections are present.

    Fix:CDATA sections are treated as text nodes by default. If your XML uses CDATA for raw character data, the output includes it as-is inside the text node — verify the parser settings match your input.

    Frequently asked questions

    References & standards