XML to JSON Converter

Convert XML to JSON in your browser under fully documented mapping rules — attributes under @attributes, repeated siblings as arrays, values kept as strings, nothing uploaded. Free, no sign-up — runs locally in your browser.

Your work is auto-saved in this browser only, so a refresh won't lose it. Nothing is uploaded.

…or drop a file onto the box above. Files are read locally, never uploaded.

What is an XML to JSON converter?

XML and JSON describe the same shape of data — a tree of named values — with different grammars and different assumptions. XML has attributes as well as elements, mixed content, comments and processing instructions; JSON has objects, arrays and typed scalars, and none of the rest. Converting between them is therefore never a purely mechanical translation: someone has to decide where the attributes live, when an array appears, and what happens to the text. This converter makes those decisions explicitly: the mapping rules are written out in full below, the conversion follows them exactly, and anything that cannot be represented is reported rather than quietly dropped.

Before anything is converted, the document is checked with the same strict well-formedness checker as this site's XML Formatter: malformed XML gets a line and column for the first problem, never a best-guess conversion.

How to use this tool

  1. Paste your XML into the box above (or press Load sample to see a worked example). You can also upload an .xml file or drop one onto the box — the file is read in your browser and never sent anywhere.
  2. Choose the JSON indent — 2 spaces is the common default; 4 spaces and tabs are one click away.
  3. Press Convert to JSON. If the document contains constructs with no JSON counterpart (comments, processing instructions), the message line tells you how many were set aside — nothing vanishes in silence.
  4. Use Copy result or Download result to take the JSON with you. Your input above is never modified — the result is a separate copy.

The mapping rules, in full

Examples

This document:

<order id="1042">
  <customer>Ada</customer>
  <item sku="A-1">2</item>
  <item sku="B-7">1</item>
  <total currency="EUR">59.90</total>
</order>

converts, by the rules above, into:

{
  "order": {
    "@attributes": { "id": "1042" },
    "customer": "Ada",
    "item": [
      { "@attributes": { "sku": "A-1" }, "#text": "2" },
      { "@attributes": { "sku": "B-7" }, "#text": "1" }
    ],
    "total": { "@attributes": { "currency": "EUR" }, "#text": "59.90" }
  }
}

Note what the rules did, visibly: the two <item> siblings became an array while <customer> — appearing once — did not; every attribute landed under @attributes; and the prices stayed strings, zeros intact.

Going the other way

If you have JSON and need XML, this site's JSON to XML Converter does the reverse trip with its own documented rules. Bear in mind that a round trip is not guaranteed to be the identity: XML has constructs JSON cannot hold (and this page tells you when it sets them aside), and JSON has types XML cannot express. Convert in the direction your consumer needs, and treat the output as the document of record.

Frequently asked questions

Is my XML uploaded anywhere?

No. Conversion happens in your browser, on this page. Nothing is sent to a server — you can disconnect from the network and the tool keeps working. Your draft is auto-saved in this browser only, for 7 days, and the Clear saved draft button deletes it immediately.

Why did my numbers and booleans come out as strings?

Because XML carries no type information: in <age>36</age>, the 36 is text that happens to look like a number, and only your application knows it is one. A converter that guesses would silently change data — 007 would become 7, 1e5 would become 100000, a 20-digit ID would lose precision. So every value stays a string, exactly as written, and typing the result is a job for the code that consumes it. The full mapping rules are written out on this page.

Where did my attributes go?

Under "@attributes", as an object keyed by attribute name: <user id="7"> becomes { "@attributes": { "id": "7" }, … }. JSON has no attribute concept, so attributes need a home that cannot collide with a child element of the same name — an element could have both an id attribute and an <id> child, and both survive the conversion, one under @attributes and one as a normal key.

Why is this child an array when that one is not?

Repeated siblings become an array, in document order; a child that appears once stays a plain value. That is the only rule that can be applied without a schema: the converter cannot know that a second <item> will arrive in tomorrow's document. If your consumer needs every <item> to be an array, normalise on the consuming side, where the expectation actually lives — the mapping rules on this page state the behaviour precisely so you can code against it.

What happened to my comments and processing instructions?

They have no JSON counterpart, so they are not converted — but they are never silently dropped either. When the input contains comments, processing instructions, a doctype or an XML declaration, the message under the tool says how many such constructs were present. Element text, attributes and CDATA content all convert; CDATA lands as ordinary text, characters exactly as authored.

My XML was rejected — why?

Because it is not well-formed: a mismatched end tag, an unclosed element, a second root element. The converter uses the same strict checker as this site's XML Formatter, and reports the line and column of the first problem. Converting malformed XML anyway would mean guessing where elements end, and a guess would produce JSON that looks plausible and is wrong — the worst outcome a converter can produce.

Can I open an .xml file instead of pasting?

Yes — use the Upload button or drag a file onto the input box. The file is read locally by your browser (it is never uploaded to a server), its contents land in the input box, and conversion runs immediately. Download result saves the JSON in the other direction.

Related tools