100% local — your data never leaves your browser

XML to JSON — Attributes Included

Convert XML to JSON. Attributes, repeated elements and text all land somewhere you can reach with a dot or a bracket in your code.

Instant Private Zero cookies
Indentation

XML input

JSON output

What this tool does

Each element becomes a key; its children become the value.

<user id="1"><name>Ada</name></user>
{ "user": { "name": "Ada", "@_id": "1" } }

Three places the models disagree

XML and JSON do not describe the same shapes, and every converter has to pick. These are the picks.

Attributes

They become keys prefixed @_. JSON has one kind of member; XML has attributes and elements, and they can share a name — <user id="1"><id>2</id></user> holds two different things both called id. The prefix keeps them apart. A toggle drops attributes if you do not need them.

When an element carries both text and attributes, the text lands under #text.

Repetition

One <item> gives an object. Two give an array.

<r><i>1</i></r>          →  { "r": { "i": 1 } }
<r><i>1</i><i>2</i></r>  →  { "r": { "i": [1, 2] } }

This is not a flaw that could be fixed; nothing in an XML document says whether an element is repeatable. Only a schema knows. If your code needs a list, normalise it on arrival.

Mixed content

This one JSON simply cannot express, and it is worth being blunt about.

<p>Hello <b>world</b> again</p>

JSON has no way to say that Hello came before <b> and again after it. The text runs are gathered under #text and their position relative to the elements is lost, along with the spacing between them. If the text is what matters — a document rather than a record — convert nothing and use the XML formatter instead.

Types

<a>1</a> gives the number 1. <a>007</a> gives the string "007", because a leading zero is usually a ZIP code or an account number, and reading it as seven loses it. A twenty-digit identifier also stays a string: a JSON number would round it.

What is not data

The XML declaration and any processing instruction are dropped. They describe the document, not its contents — a ?xml key sitting beside your root element was never information you asked for.

Private by design

Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.

Frequently asked questions

Why did my single <item> become an object instead of an array?
Because nothing in an XML document says whether an element repeats. One `<item>` looks exactly like a list of one, and only a schema knows the difference. Two or more become an array; one becomes an object. If your consumer needs a list either way, normalise it there — `Array.isArray(x) ? x : [x]` is the usual line.
Why are attributes prefixed with @_?
Because JSON has one kind of member and XML has two. `<user id="1"><id>2</id></user>` has an attribute and an element that are both called `id` and are not the same thing; without a prefix one would overwrite the other. The toggle drops attributes entirely if you would rather not see them.
Why did <a>007</a> stay a string while <a>7</a> became a number?
Because the leading zero is almost always load-bearing — a ZIP code, an account number, a part reference. Reading `007` as the number seven loses it for good. A number without leading zeros is converted; anything a JSON number cannot hold exactly, such as a twenty-digit identifier, stays a string for the same reason.

Related converters