Skip to main content
File & Data Conversion Tools

XML to JSON Converter

Convert XML to JSON - nested elements become nested objects, attributes are preserved, repeated elements become arrays.

Paste or upload XML below - this tool parses it with your browser's built-in, safe XML parser and converts the structure to JSON.

External entities and DTD-based network requests are never resolved by this tool - browser XML parsing is inherently safe against XXE-style attacks by default.

How the Conversion Works

Each XML element becomes a JSON object key; attributes are captured under an @attributes key; repeated sibling elements with the same name become a JSON array; an element's plain text content becomes its value (or a #text key when the element also has attributes/children).

How to Use It

  1. Paste or upload XML data.
  2. Click Convert.
  3. Copy or download the resulting JSON.

Security Notes

XML parsing here uses the browser's native DOMParser, which does not fetch external DTDs or resolve external entities - your XML is never used to make outbound network requests, protecting against XXE-style attacks.

Example

<book id="7">
  <title>Dune</title>
  <tag>sci-fi</tag>
  <tag>classic</tag>
</book>

becomes a structure like:

{
  "book": {
    "@attributes": {
      "id": "7"
    },
    "title": "Dune",
    "tag": [
      "sci-fi",
      "classic"
    ]
  }
}

The attribute is kept under @attributes, and the two <tag> elements become an array.

Common Uses

  • Working with SOAP responses, RSS/Atom feeds or sitemaps in JavaScript.
  • Migrating data from an XML-based system to a JSON API or document database.
  • Reading a large XML document more easily - JSON is often shorter.

Things to Watch

  • An element that appears once becomes a single value, and the same element repeated becomes an array. If your code expects an array, handle both shapes.
  • All values are text in XML, so "1965" stays a string - convert types in your code.
  • Namespaced names such as dc:creator keep their prefix as part of the key.

Convert back with JSON to XML. For a flat table, use XML to CSV.

Frequently Asked Questions

Attributes are kept under an "@attributes" property on the element's object, separate from its child elements.

The converter only creates an array when an element repeats. If some records have one child and others many, check the output shape before relying on it in code.

XML text has no types, so values are best treated as strings unless you convert them yourself.
Share this tool: