XML to JSON

XML tree to JSON object (attributes prefixed with @).

{{ xmlToJson.message }}

Overview

XML and JSON are two fundamentally different data models, not just two different text formats. XML is a tree model with element nodes, text nodes, attributes, and comments — each element can contain text, attributes, AND children at the same time, the so-called mixed content. JSON is simpler: strings, numbers, booleans, null, arrays, and objects. This structural difference is what makes XML-to-JSON conversion non-trivial: there is no universal lossless mapping, and any tool that claims otherwise is oversimplifying.

The conversion is especially useful when you consume a legacy API or a SOAP system that returns XML, but want to work with the data in JavaScript, Python, or any language where JSON is a first-class citizen. JSON format is easier to navigate with modern code: `data.user.name` is more readable than traversing a DOM tree with `getElementsByTagName`. Integration platforms like MuleSoft, Apache Camel, and AWS Step Functions perform this kind of conversion internally all the time.

The convention this tool uses: XML attributes become keys prefixed with `@` (for example, `@id`), the text content of an element becomes the `#text` key, and child elements become nested objects. When multiple children share the same tag name, they become an array. XML namespaces (the `ns:` prefix) are preserved as part of the key name. This is one of the most common conventions, but not a universal one — libraries like xml2js, fast-xml-parser, and xmltodict offer different configurable options, so review the generated JSON before using it in production code.

This tool runs entirely in the browser. For XML with complex namespaces, CDATA sections, comments, or external entities, the result may need manual adjustment. The ideal use case is relatively straightforward XML: API responses, configuration files, RSS feeds, or legacy system exports. Paste, convert, and use as the starting point in your code.

Technical deep dive

Common questions summarized

  • What is this tool for?: It runs fully in your browser: useful to validate, format, or convert data in everyday development.
  • Are my inputs sent to a server?: Processing happens locally with JavaScript. We do not store what you paste into the text areas.
  • Can I use this for real production data?: Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.

Sample payload to try

  • See also the larger "Code Snippets" sample; paste this excerpt to try locally: Sample — <user id="1"><name>Ada</name></user>

Tool guide

  • What XML is Tree of elements, attributes, and text.

  • What JSON is An alternative view of the same tree, more common in web APIs. Attributes often use a prefix convention (e.g. @).

  • What the converter does Reads XML and emits a JSON object that reflects the structure.

  • Why use it Consume XML legacy in JSON-first apps, quick tests, and one-off transforms. Namespaces or mixed content may need manual cleanup.

Code Snippets

Code example
<user id="1"><name>Ada</name></user>

Sample

<user id="1"><name>Ada</name></user>

FAQ

What is this tool for?

It runs fully in your browser: useful to validate, format, or convert data in everyday development.

Are my inputs sent to a server?

Processing happens locally with JavaScript. We do not store what you paste into the text areas.

Can I use this for real production data?

Use at your own risk. For secrets (passwords, tokens), prefer controlled environments and your company policies. And always review the generated contents. Never trust blindly things you see on the internet.