Skip to content
Tools

XML to JSON Converter

Convert XML documents into clean, structured JSON instantly with support for attributes, nested elements and large XML files. Everything runs locally in your browser.

Search in
Visible pane

Paste XML or upload an .xml file to convert it into JSON.

Waiting for input

There is nothing to convert.

Paste an XML document, or load a sample to see what the converter does.

Everything happens locally in your browser. Your data is never uploaded.

What is XML to JSON?

Converting XML to JSON means reading a markup document and rebuilding the same information as JSON data: elements become keys, their text becomes values, and nesting becomes nesting.

It is the harder direction of the two. Going from JSON to XML, every JSON construct has somewhere to go. Coming back, XML carries three things JSON has no slot for — attributes, mixed content, and the difference between one child and a list of one — so a converter has to invent conventions. Every XML-to-JSON tool invents slightly different ones, which is why the same document converted by two tools rarely matches.

XML
<user id="1042">  <name>Ada Lovelace</name>  <city>London</city></user>
The same data as JSON
{  "user": {    "@id": "1042",    "name": "Ada Lovelace",    "city": "London"  }}

Two decisions are already visible. The id attribute became @id, marking it as having come from an attribute rather than a child element — because otherwise it would be indistinguishable from <id>1042</id>. And "1042" is a string, not a number, because XML never said it was one.

Why convert XML to JSON?

Because JSON is what the receiving code wants to work with. XML is what a great deal of existing, working software still emits, and the gap between the two is where conversion lives.

  • It is native to JavaScript. JSON parses into ordinary objects with no library and no traversal API. Working with XML in a browser means DOM methods, node lists and namespace-aware lookups.
  • It is smaller. XML writes every name twice. Dropping the closing tags typically takes a third off, which matters on every request.
  • It is easier to store. Document databases, message queues and log pipelines mostly speak JSON. Converting on arrival means one format inside your system rather than two.
  • It contains the boundary. Converting once, at the edge, keeps XML out of the rest of the codebase — which is what makes eventually replacing the XML source a small change rather than a rewrite.
  • It is easier to read. For inspecting an unfamiliar payload, a JSON tree beats angle brackets, which is why this tool has one built in.

How XML to JSON conversion works

  1. 1. The XML is parsed. The document is read into a tree of elements, attributes and text. If it is not well-formed, conversion stops here and the problem is reported with its line and column — a half-parsed document would produce JSON that quietly omitted whatever came after the mistake. The XML formatter is the easier place to track down a well-formedness error in a long document.
  2. 2. Entities are resolved. &amp; becomes &, &#169; becomes ©, and CDATA sections are taken literally. This happens during parsing, so the values that reach the conversion are already the real text.
  3. 3. Each element is converted, children first. An element with only text becomes that text. An element with attributes or children becomes an object holding both.
  4. 4. Repeated names collapse into arrays. The first <item> is stored directly; the second turns it into an array and appends. This is why the output shape depends on how many items the document happened to contain.
  5. 5. Whitespace is discarded where it means nothing. Indentation between tags is formatting, not content, so it is dropped. Text inside CDATA never is.

That last step is worth dwelling on. In pretty-printed XML, every pair of tags has a newline and some spaces between them. Treating those as text would give almost every element a #text of "\n " and make the output unusable — so ordinary text is trimmed and dropped when empty, while anything inside a CDATA section is kept exactly as written.

XML vs JSON

XML is a document format that grew out of publishing; JSON is a data format that grew out of a programming language. Nearly every difference follows from that.

  • Types. JSON has numbers, booleans, strings and null. XML has text. This is the single biggest thing gained in one direction and lost in the other, and the reason every value here comes out as a string.
  • Arrays. JSON has them. XML expresses repetition by convention, which is why converting has to guess from the number of siblings present.
  • Attributes. XML has two places to put a value; JSON has one. Bridging that needs a naming convention, and no convention is standard.
  • Comments. XML has them; JSON does not. They are dropped, and counted so you can see they existed.
  • Mixed content. Text with markup inside it is natural in XML and has no JSON equivalent. Documents tend to stay XML for exactly this reason.
  • Size and speed. JSON is smaller and faster to parse. XML is more expressive about documents. Neither fact makes one correct.

The conversion is therefore not quite lossless. Comments, the declaration, processing instructions, the element-versus-attribute distinction and whitespace between tags do not survive in full. Everything that carries data does.

How XML attributes are converted

This is the decision that most distinguishes one converter from another, because JSON has no concept of an attribute. Consider:

One element, one attribute, one child
<user id="1042">  <id>internal-7</id></user>

Both the attribute and the child are called id, and they mean different things. Writing both as plain keys would collide. The two common answers are:

Prefixing

Attributes get a marker character, conventionally @. The document above becomes:

{  "user": {    "@id": "1042",    "id": "internal-7"  }}

Flat, readable, and each attribute stays next to the elements it sits with. The cost is that @is awkward in some languages’ property access, and a JSON key genuinely starting with @ would be ambiguous.

Grouping

Attributes are collected into a nested object instead:

{  "user": {    "_attributes": { "id": "1042" },    "id": "internal-7"  }}

Unambiguous, and easy to iterate over as a set. The cost is an extra level of nesting on every element that has attributes, and paths that get longer.

Both are offered here, with the prefix and the group key editable, because the right answer depends entirely on what reads the JSON afterwards. If you are feeding a schema or a library that already expects one convention, match it — the conversion is easy to redo, and reshaping the output downstream is not.

Whichever you pick, the JSON viewer is a quick way to check the shape that came out, and the JSON to XML converter goes back the other way when something downstream wants XML again.

Supported XML features

Everything below is handled, and each is shown with what it becomes.

Elements

An element with nothing but text becomes that text. This is what keeps the output readable rather than wrapping every value in an object of its own.

XML
<name>Ada</name>
JSON
{ "name": "Ada" }

Attributes

Attributes have no natural home in JSON, so they get a prefix or a nested object — your choice. Prefixed is shown here.

XML
<user id="1042">Ada</user>
JSON
{  "user": {    "@id": "1042",    "#text": "Ada"  }}

Repeated elements

Two or more siblings sharing a name become an array. One stays a single value, because XML cannot express a list of one.

XML
<tags>  <tag>api</tag>  <tag>xml</tag></tags>
JSON
{  "tags": {    "tag": ["api", "xml"]  }}

Nested elements

Nesting maps across directly, to any depth. An element containing elements becomes an object containing keys.

XML
<address>  <city>London</city></address>
JSON
{  "address": {    "city": "London"  }}

CDATA

Content comes through literally — markup, ampersands and whitespace intact — which is exactly what CDATA is for.

XML
<html><![CDATA[<b>bold</b>]]></html>
JSON
{ "html": "<b>bold</b>" }

Namespaces

Prefixes are preserved by default and can be stripped in the options. Declarations arrive as ordinary attributes.

XML
<soap:Body xmlns:soap="urn:x">1</soap:Body>
JSON
{  "soap:Body": {    "@xmlns:soap": "urn:x",    "#text": "1"  }}

The XML declaration, processing instructions, comments and DOCTYPE are all recognised and skipped: they describe the document rather than carrying data, and JSON has nowhere to put them. A DOCTYPE that declares custom entities is not applied, and the tool says so rather than failing silently on &myEntity;.

Common use cases

Conversion happens at boundaries — wherever something that speaks XML has to hand data to something that speaks JSON.

SOAP API migration

A SOAP response is XML by definition. Converting it to JSON at the client boundary means the rest of the application never has to know, which is usually the first step in moving off SOAP entirely.

Legacy system integration

Software written before JSON existed emits XML and will not change. Converting on arrival lets a modern service consume it without carrying an XML parser through its whole codebase.

REST APIs

A gateway that accepts XML from upstream and serves JSON downstream is a common shape. The conversion is the gateway's entire job.

Mobile applications

Mobile clients work in JSON natively and pay for every byte over the air. Converting server-side sends less and saves the device the work of parsing markup.

Data migration

Exports from older systems — catalogues, records, configuration dumps — arrive as XML. Converting them is the first step before loading into anything that stores JSON.

Configuration files

Build tools and application servers still emit XML configuration. Reading it as JSON makes it far easier to inspect, diff and manipulate with ordinary scripting.

Frequently asked questions

Is this XML to JSON converter free?

Yes. Conversion, every option, the tree view, statistics, search, uploads and downloads are all free, with no account, no usage cap and no paid tier. Nothing is held back.

Is my XML uploaded anywhere?

No. Everything happens inside your browser. The document you paste, drop or open is parsed and converted by JavaScript running on your own machine — it is never sent over the network, stored or logged. You can confirm this by watching your browser's network panel, or by disconnecting from the internet after the page loads: the converter keeps working.

Is the converted JSON valid?

Yes. The output is produced by a serialiser rather than by string concatenation, so quotes, backslashes and control characters inside your values are escaped correctly. If the XML parses, the JSON is valid — and you can check it yourself by pasting the result into the JSON Validator.

Can I convert XML attributes?

Yes, and you choose how. Prefixed mode puts each attribute on the element's own object under a prefix, so id="1" becomes "@id": "1". Grouped mode collects them into a nested object instead, as "_attributes": { "id": "1" }. Both prefix and key name are editable, because different downstream consumers expect different conventions.

Will repeated elements become arrays?

Yes, automatically. Two or more sibling elements sharing a name become a JSON array. One does not — a single <user> stays an object. That is inherent to the conversion rather than a choice: XML has no way to say "this is a list that happens to have one item in it", so the shape follows the data. If your consumer needs a guaranteed array, normalise it after conversion.

Does it support namespaces?

Yes. Prefixed names such as soap:Body are preserved by default, so the JSON key is "soap:Body". Turn off "Keep namespace prefixes" and the prefix is stripped, leaving "Body", which is usually what you want when the namespace carries no meaning downstream. Namespace declarations themselves — xmlns and xmlns:prefix — come through as ordinary attributes.

What happens to CDATA sections?

The content comes through exactly as written, including markup, ampersands and surrounding whitespace. That is the whole point of CDATA: everything inside it is literal text rather than markup, so <![CDATA[<b>hi</b>]]> becomes the string "<b>hi</b>" rather than a nested element.

Why are my numbers strings?

Because XML has no types. <count>42</count> contains the characters 4 and 2, and nothing in the document says whether that is a number, a version, a product code or a string that happens to look numeric. Converting it to 42 would be a guess, and a damaging one for values like "007" or "1.10". Every value comes out as a string; coerce the fields you know about after conversion.

What happens to comments and the XML declaration?

Both are skipped. They describe the document rather than carrying data, and JSON has no equivalent for either — there is no comment syntax to put them in. The statistics panel counts how many comments were in the source so you can see nothing was lost quietly.

Can I convert large XML files?

Yes. Documents up to roughly 20 MB are supported, and a megabyte parses in about fifty milliseconds. The parser is iterative rather than recursive, so deeply nested documents convert without overflowing the stack, and the editors only render the lines currently on screen.

What happens if my XML is invalid?

Nothing is converted, and the tool tells you exactly what went wrong: a mismatched or unclosed tag, an unquoted attribute value, an unescaped ampersand, an unclosed CDATA section or comment, a bad namespace prefix. Each comes with the line, the column, the offending line marked, and a plain-language explanation of the fix.

Why does an unescaped & fail?

Because in XML an ampersand always starts an entity reference. A literal one has to be written &amp;, and XML predefines only five entities — &amp; &lt; &gt; &quot; and &apos; — plus numeric references like &#169;. Anything else, &nbsp; being the usual culprit, needs a DTD that this converter does not read. It is by far the most common reason a document fails to parse.

Can I remove the root element?

Yes. XML requires a single root wrapper; JSON does not. Turn off "Preserve root element" and the wrapper is dropped, returning its contents directly — useful when the root is a meaningless <response> or <envelope> and only what is inside it matters.

Can I download the JSON?

Yes. The download button saves the formatted result as data.json, and the copy button puts whichever view you are looking at on your clipboard. Both are also on keyboard shortcuts, listed in the options panel.

Does the converter work offline?

Once the page has loaded, yes. All parsing and conversion is local, so you can disconnect and keep working. A connection is only needed to load the page in the first place.

Popular tools

↑ ↓NavigateOpenEscClose