Attributes:
Text nodes:

Input — paste your XML

Output — JSON

All conversion is done in your browser using the DOM parser. No data is sent to any server.

How XML to JSON Conversion Works

XML and JSON represent the same kinds of data — nested structures, lists, and key-value pairs — but with fundamentally different syntax. XML uses opening and closing tags, supports attributes on elements, and treats text content as a node value. JSON uses braces and brackets, has no concept of attributes, and text is just a string value.

Converting between them requires decisions about how to handle XML-specific features that have no direct JSON equivalent. This tool uses two options you can toggle: how XML attributes are mapped (prefixed with @ or ignored), and how mixed-content text nodes are handled. Use the JSON Formatter to clean up the output further once you have your converted JSON.

Worked Example

XML input

<user id="42">
  <name>Alice</name>
  <roles>
    <role>admin</role>
    <role>editor</role>
  </roles>
</user>

JSON output

{
  "user": {
    "@id": "42",
    "name": "Alice",
    "roles": {
      "role": [
        "admin",
        "editor"
      ]
    }
  }
}

Attribute Handling

XML attributes have no direct equivalent in JSON. The most common convention is to prefix them with @ — so id="42" on an element becomes "@id": "42" in the JSON object. This preserves all data. The alternative is to ignore attributes entirely, which produces cleaner JSON at the cost of losing attribute data — useful when you know the attributes are irrelevant metadata like namespace declarations.

Repeated Elements Become Arrays

When the same tag appears multiple times at the same level, the converter automatically groups them into a JSON array. A single <role> tag produces a string; two or more produce an array. This is standard behaviour for XML-to-JSON conversion and matches how most XML APIs intend the data to be consumed.


Frequently Asked Questions

How does this tool handle XML attributes?
By default, XML attributes are preserved using the @ prefix convention. An element like <user id="42"> becomes {"@id": "42", ...} in the JSON output. You can switch to "ignore" mode to strip all attributes, which produces cleaner JSON when the attributes are not relevant to your use case.
Why do some elements become arrays in the JSON output?
When an XML element appears multiple times at the same level, the converter groups them into a JSON array. For example, three <item> tags inside a <list> element become "item": ["a", "b", "c"]. A single occurrence stays as a string or object. This is the standard approach and matches how most XML-consuming APIs structure their data.
What happens to the XML declaration and comments?
The XML declaration (<?xml version="1.0"?>) is a processing instruction, not data, and is ignored during conversion. XML comments (<!-- ... -->) are also ignored — JSON has no equivalent for comments, so there is nowhere to put them in the output. The conversion only processes element nodes, text content, and attributes.
How does the tool handle XML namespaces?
Namespace prefixes are preserved as part of the key name. An element <ns:item> becomes the JSON key "ns:item". Namespace declarations (xmlns:ns="...") are treated as regular attributes and either prefixed with @ or ignored depending on your attribute mode setting.
Can I convert JSON back to XML?
This tool converts XML to JSON only. The reverse — JSON to XML — requires additional decisions about how to map JSON arrays back to repeated elements, how to handle JSON keys that aren't valid XML tag names, and what root element to use. A dedicated JSON-to-XML converter is better suited for that direction.
What is the difference between XML and JSON?
Both XML and JSON represent structured data, but they have different strengths. XML supports attributes, comments, namespaces, mixed content (text alongside child elements), and has strong tooling for validation via schemas (XSD). JSON is simpler, more compact, natively supported in JavaScript, and has become the default for REST APIs. XML remains common in enterprise systems, SOAP web services, document formats like SVG and DOCX, and configuration files like Maven's pom.xml.