Convert XML to JSON Instantly

Paste XML data or upload a file to get formatted JSON output. Handles nested elements, attributes, and CDATA sections.

100% client-side. Your data never leaves your device.
XML Input
JSON Output

How to Convert XML to JSON

Converting XML (Extensible Markup Language) to JSON (JavaScript Object Notation) is a common task for developers integrating APIs, migrating data, or working with modern web services. Here is how to do it with this free online tool:

  1. Paste or upload your XML data. Either paste your XML text directly into the input panel, or click the "Upload File" button to load an .xml file from your computer.
  2. Choose your options. Toggle "Include attributes" to convert XML attributes into @attr properties. Enable "Trim whitespace" to clean up extra spaces. Use "Minify JSON" for compact output.
  3. Get your JSON instantly. The conversion happens automatically as you type or paste. The JSON output appears in the right panel in real time, with element and attribute counts displayed above it.
  4. Copy or download the result. Click "Copy JSON" to copy the output to your clipboard, or click "Download JSON" to save it as a .json file.

The entire conversion runs in your browser using the built-in DOMParser API. Your data is never uploaded to a server or stored anywhere.

When to Use XML vs JSON

Both XML and JSON are popular data interchange formats, but they have different strengths. Here is a quick comparison:

Feature XML JSON
SyntaxVerbose, tag-based markupLightweight, curly braces and brackets
AttributesSupports attributes on elementsNo native attribute concept
Data typesEverything is textStrings, numbers, booleans, null, arrays
NamespacesFull namespace supportNot supported
CommentsSupportedNot supported
File sizeLarger due to closing tagsSmaller, more compact
ParsingRequires XML parser (DOM/SAX)Native JSON.parse() in JavaScript
Best forDocument markup, SOAP APIs, config filesREST APIs, web apps, data storage

Use XML when working with SOAP web services, document-centric data with mixed content, or systems that require schema validation (XSD) and namespaces.

Use JSON when building REST APIs, storing configuration, or exchanging data between web applications. JSON is the default for modern web services and is natively supported by JavaScript.

How XML Attributes and Elements Map to JSON

XML and JSON have fundamentally different data models, so conversion requires some conventions:

Element text content

Simple elements like <name>Alice</name> become {"name": "Alice"}. If an element has only text content and no attributes, it maps to a plain string value.

Attributes

Attributes are prefixed with @ to distinguish them from child elements. For example, <user id="1"> becomes {"@id": "1"}. When an element has both attributes and text content, the text is stored under a #text key.

Repeated elements

Sibling elements with the same tag name are automatically grouped into JSON arrays. For example, multiple <item> elements become a single "item": [...] array.

Mixed content

Elements with both text and child elements store text under the #text key alongside the child element properties.

Frequently Asked Questions

How do I convert XML to JSON?
Paste your XML data into the input panel or upload an .xml file. The tool automatically converts it to JSON in real time. You can then copy the JSON to your clipboard or download it as a .json file.
Is my data safe when using this converter?
Yes. All conversion happens locally in your browser using JavaScript's built-in DOMParser. Your data is never sent to any server, stored, or tracked. It never leaves your device.
How are XML attributes handled?
XML attributes are converted to JSON properties prefixed with @. For example, <item id="1"> becomes {"@id": "1"}. You can toggle attribute handling on or off in the options bar.
What happens with nested XML elements?
Nested XML elements are converted to nested JSON objects. Repeated sibling elements with the same tag name are automatically grouped into JSON arrays.
Does the converter handle CDATA sections?
Yes. CDATA sections are treated as text content and included in the JSON output as string values, preserving the original text within them.