Conversion Tools

XML to JSON

This free XML to JSON converter parses your XML with the browser's built-in parser and outputs 2-space indented JSON, keeping attributes under an @attributes key, text under #text, and turning repeated tags into arrays. Paste markup or upload a .xml file; everything runs locally, so nothing is uploaded.

Runs in your browser. Your files and text never leave your device - nothing is uploaded.

Upload XML file
Click or drag & drop · .xml, .txt

Convert XML to JSON Online

The Tools Kit’s free XML to JSON converter turns an XML document into readable, two-space indented JSON. Paste your markup or upload a .xml file, click Convert, and copy the result. Attributes are kept under an @attributes key, text content goes under #text, and repeated tags become arrays, so the structure of the original document survives the conversion.

The XML is parsed by your browser’s built-in XML parser and converted on your device. Nothing is uploaded, there is no signup, and malformed markup is reported as an “Invalid XML” error instead of producing broken output.

How to Convert XML to JSON

  1. 1

    Add your XML

    Paste a well-formed XML document into the XML Input box, or upload or drag in a single .xml or .txt file. An uploaded file loads into the box and converts straight away.

  2. 2

    Click Convert

    Press Convert to parse pasted XML. The JSON appears in the JSON Output panel, pretty-printed with two-space indentation.

  3. 3

    Fix any errors

    If the markup is not well-formed, a red "Invalid XML" message appears and no JSON is produced. Close or correct the offending tag and click Convert again.

  4. 4

    Copy the JSON

    Click Copy JSON to put the result on your clipboard, or Clear to empty the input, the output, and the uploaded file name and start over.

If the XML is hard to read before you convert it, tidy it first with the XML formatter, which also shows whether the document is well-formed.

How XML Maps to JSON: A Worked Example

XML and JSON describe data differently: XML has elements, attributes, and text, while JSON only has objects, arrays, strings, numbers, booleans, and null. Any XML to JSON converter has to pick a convention. This one follows these rules:

  • The root element is unwrapped. The output object is the root’s contents, so the outer tag name does not appear.
  • Child elements become keys named after their tag, including any namespace prefix such as soap:Body.
  • Text goes under #text, trimmed. Whitespace-only text between tags is ignored.
  • Attributes go under @attributes, one string per attribute.
  • Repeated sibling tags become an array; a tag that appears once stays a single object.
  • An empty element such as <note/> becomes an empty object {}.

Converting this catalog:

<catalog>
  <book id="b1" lang="en">
    <title>XML Basics</title>
    <price>29.99</price>
  </book>
  <book id="b2">
    <title>JSON Guide</title>
  </book>
</catalog>

produces the JSON below (shown slightly compacted; the tool puts each key on its own line). The catalog root is unwrapped, the two book elements become an array, and the price stays the string "29.99".

{
  "book": [
    {
      "@attributes": { "id": "b1", "lang": "en" },
      "title": { "#text": "XML Basics" },
      "price": { "#text": "29.99" }
    },
    {
      "@attributes": { "id": "b2" },
      "title": { "#text": "JSON Guide" }
    }
  ]
}

Going the other way? The JSON to XML converter builds markup from a JSON object.

Data Types, Mixed Content, and Other Limits

XML has no notion of numbers or booleans, so every value in the output is a string. <age>30</age> becomes "#text": "30", and active="true" becomes the string "true". Cast the fields you need in your own code after converting.

In mixed content, such as <p>Hi <i>there</i> you</p>, the separate text runs are gathered into a #text array (["Hi", "you"]) next to the i element, so the original word order between text and tags is not recorded. Comments appear as empty #comment entries and the content of CDATA sections is not carried over, so strip comments and replace CDATA with escaped text if that content matters. The HTML entity encoder can escape characters like & and < for you.

The tool converts one document at a time and always outputs two-space indentation. To validate, reformat, or minify the result, paste it into the JSON formatter.

XML vs JSON: Why Convert?

XML still powers SOAP web services, RSS and Atom feeds, sitemaps, Office file internals, and many enterprise and government data exports. Most modern web APIs and JavaScript code expect JSON, which is lighter to read and maps straight onto objects and arrays. Converting XML to JSON lets you inspect a legacy payload, build a test fixture, or plan the data model before writing a parser.

Data rarely arrives in just one format. If yours comes as YAML, use the YAML to JSON converter; for spreadsheet exports, the CSV to JSON converter turns rows into objects, and the JSON to CSV converter flattens an array of objects back into a table. The full set lives under conversion tools.

Common uses

  • Turning a SOAP or XML API response into JSON to inspect or use in JavaScript
  • Converting an RSS feed or sitemap snippet into JSON for a script or test fixture
  • Seeing how a config file’s attributes and nested elements map to keys before writing parser code
  • Checking whether an XML document is well-formed, since bad markup returns an Invalid XML error
  • Migrating legacy XML data exports into a JSON-based app or database

XML to JSON terms explained

TermWhat it means here
Root elementThe single outermost XML element. Its tag name is not repeated in the output; the JSON object you get is its contents.
@attributesThe key that holds an element’s attributes, one string value per attribute name
#textThe key that holds an element’s text content, trimmed of surrounding whitespace
ArrayWhat a key becomes when the same tag appears more than once among siblings
Well-formed XMLMarkup with one root, every tag closed, tags properly nested, and special characters escaped; the only kind the parser accepts
Mixed contentAn element that holds both text and child elements, such as a paragraph with bold words inside it

Frequently Asked Questions

Reviewed by Raja Jahangir · Last reviewed: October 7, 2026

How do you convert XML to JSON?

To convert XML to JSON, paste the XML or upload a .xml or .txt file and click Convert. The root element is unwrapped, child elements become object keys, text is stored under a #text key, repeated siblings become arrays, and attributes go under an @attributes key. Malformed markup is reported as Invalid XML.

How are XML attributes handled in JSON?

XML attributes have no direct JSON equivalent, so they are placed in a nested @attributes object on the element they belong to. For example, a child element <user id="7">Alice</user> becomes "user": {"@attributes": {"id": "7"}, "#text": "Alice"}. All values stay strings; numbers and booleans are not type-converted.

Sources and standards