XML to JSON Converter

Or enter XML manually below

Cleared

How XML to JSON Converter Works?

What's a valid XML input for this tool?

This tool accepts any valid XML with a single root element:

<tool>
  <name>Google Sheets</name>
  <category>Spreadsheet</category>
  <pricing>Free</pricing>
</tool>

Note: The XML must have exactly one root element. If your XML has multiple root elements, wrap them in a single parent tag.

What does the output look like?

Each XML element becomes a JSON key, and its content becomes the value. The result of the above XML will be:

{
    "tool": {
        "name": "Google Sheets",
        "category": "Spreadsheet",
        "pricing": "Free"
    }
}

How are attributes handled?

If your XML element has attributes, they are grouped under the $ key in the JSON output.

<tool id="excel-365" platform="windows">
  <name>Microsoft Excel</name>
</tool>

becomes:

{
    "tool": {
        "$": {
            "id": "excel-365",
            "platform": "windows"
        },
        "name": "Microsoft Excel"
    }
}

What if an element has both attributes and text?

When an element has attributes or child elements along with text content, the text is stored under the _ key.

<price plan="pro">9.99</price>

becomes:

{
    "price": {
        "$": {
            "plan": "pro"
        },
        "_": "9.99"
    }
}

How are repeated elements handled?

When multiple elements share the same name, they are automatically converted into a JSON array.

<productivity-tools>
  <tool>Notion</tool>
  <tool>Trello</tool>
  <tool>Airtable</tool>
</productivity-tools>

becomes:

{
    "productivity-tools": {
        "tool": ["Notion", "Trello", "Airtable"]
    }
}

Note: Single elements remain as objects, not arrays. Arrays are only created when there are multiple elements with the same name.

Does it support CDATA sections?

Yes, CDATA sections are treated as text content. This is useful for including code or special characters.

<formula><![CDATA[
  =IF(A1>100, "High", "Low")
]]></formula>

becomes:

{
    "formula": "=IF(A1>100, \"High\", \"Low\")"
}