Convertee/Guide

How to Convert XML to JSON: Complete Guide

Last updated: 2026-04-14

XML has been the backbone of enterprise data exchange for decades — SOAP APIs, RSS feeds, configuration files, and government data exports all rely on it. But modern web applications overwhelmingly prefer JSON. When you receive an XML payload and need to work with it in JavaScript, Python, or any language with native JSON support, conversion is the fastest path forward.

Step-by-Step: Convert XML to JSON with Convertee

  1. Open Convertee and select XML as the source format and JSON as the target.
  2. Paste your XML document into the input panel, or drag-and-drop an .xml file.
  3. Review the conversion options — attribute handling, text node key naming, and array detection.
  4. Press Convert (Cmd+Enter).
  5. Copy the resulting JSON or download it as a .json file.

Convertee processes your XML entirely in the browser. Nothing is sent to a remote server — your data stays on your machine.

Understanding the Formats

XML

XML (Extensible Markup Language), defined by the W3C XML 1.0 specification, uses nested elements with opening and closing tags to represent hierarchical data. Elements can carry attributes, namespaces, and mixed content (text interleaved with child elements). While expressive, this complexity makes XML verbose compared to JSON.

JSON

JSON (RFC 8259) maps data to objects, arrays, strings, numbers, booleans, and null. It has no concept of attributes or namespaces, so the conversion process must decide how to represent those XML-specific features. Common conventions include prefixing attribute keys with @ and storing text content under a #text key.

Before / After Example

Input XML:

<catalog>
  <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <price>44.95</price>
  </book>
  <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <price>5.95</price>
  </book>
</catalog>

Output JSON:

{
  "catalog": {
    "book": [
      {
        "@id": "bk101",
        "author": "Gambardella, Matthew",
        "title": "XML Developer's Guide",
        "price": "44.95"
      },
      {
        "@id": "bk102",
        "author": "Ralls, Kim",
        "title": "Midnight Rain",
        "price": "5.95"
      }
    ]
  }
}

Common Use Cases

Options and Configuration

OptionDefaultWhat It Does
Attribute prefix@Prefix added to XML attribute names in the JSON output (e.g., an attribute id becomes @id).
Text node key#textKey used for text content when an element has both attributes and text.
Force arraysOffWhen enabled, single child elements are always wrapped in an array for consistent structure.
JSON indent2 spacesControls the indentation of the JSON output. Choose 2 or 4 spaces, tabs, or minified.

Frequently Asked Questions

How does Convertee handle XML attributes?
By default, XML attributes are prefixed with '@' in the JSON output. For example, <book id="101"> becomes { "@id": "101" }. You can change the prefix character in the options.
What happens with XML namespaces?
Namespace prefixes are preserved as part of the element name in the JSON output. For example, <ns:element> becomes a key named 'ns:element'. Full namespace URI resolution is not performed.
Can I convert XML with mixed content (text and child elements)?
Yes. When an element contains both text and child elements, the text content is stored under a '#text' key alongside the child elements in the JSON object.
Is my XML data sent to a server?
No. Convertee parses and converts your XML entirely in the browser using JavaScript. Your data never leaves your machine.

Related Guides

Ready to convert? Try it now — no sign-up required.

Open Converter