Skip to content
Tools

XML to JSON Converter

Last updated:

Paste XML and get JSON where each element becomes a key, repeated sibling elements become an array, and attributes are kept as prefixed keys so no data is lost. Malformed XML is reported with its line number instead of half-converted.

Runs in your browser: your XML never leaves your device – nothing is uploaded, logged or stored on a server. How we protect your data

100% in-browserNothing is uploaded

Input

Loading editor…

Paste XML here

or drop a file anywhere in this box. Everything stays in your browser.

Drop a file to load it

Output

Loading editor…

JSON appears here

Results update as you type.

How to use the XML to JSON

  1. Paste XML or drop an .xml file (SOAP responses, RSS feeds, sitemaps, config).
  2. Check attribute handling: attributes appear as keys with a prefix such as @.
  3. Look at elements that occur once but can repeat elsewhere; they may need to be forced into arrays in code.
  4. Copy or download the JSON.

Worked example

A note with attributes and a repeated element

XML

<note id="n1" lang="en">
  <to>Ada</to>
  <tag>urgent</tag>
  <tag>work</tag>
</note>

JSON

{
  "note": {
    "@id": "n1",
    "@lang": "en",
    "to": "Ada",
    "tag": [
      "urgent",
      "work"
    ]
  }
}

tag occurs twice, so it becomes an array; to occurs once and stays a string. The attribute prefix is @ by default and can be changed in the options, as can the #text key.

XML constructs and their JSON form

XML constructs and their JSON form
XMLJSON
<a>text</a>"a": "text"
<a x="1">text</a>"a": {"@x": "1", "#text": "text"}
<a/> or <a></a>"a": null
<n>42</n>, <b>true</b>42 and true with number detection on (default); "42" and "true" with it off
Repeated <a> siblings"a": [ … ]
Namespaced <soap:Body>Key "soap:Body" (prefix kept)
Comments and processing instructionsDropped

The single-item array problem

XML has no array marker, so a converter can only infer arrays from repetition. An order with two <item> elements gives "item": [...], but an order with one gives "item": {...}. Code that loops over item then breaks on single-item documents. Normalize in your code (wrap non-arrays in an array) for every element the schema allows to repeat.

Mixed content and types

Text interleaved with child elements, as in <p>Hello <b>world</b>!</p>, is document markup rather than data and does not map cleanly; the text parts are collected under a #text key and their order relative to the children is lost. All XML values are text; with number detection on (the default) 42 and true become JSON values, and turning it off keeps them as "42" and "true". Attribute values follow the same rule.

Entities declared in an inline DTD are a common source of surprises; if a value shows a raw &name; reference, replace it with the actual text before converting.

XML to JSON FAQ

How are XML attributes converted to JSON?

Each attribute becomes a key on the element's object with a prefix (commonly @) so it cannot collide with a child element of the same name.

Why is an element sometimes an array and sometimes an object?

Arrays are inferred from repeated siblings. A list with one entry looks like a single element in XML. Handle both shapes in code, or force known list elements into arrays.

Can I convert a SOAP response to JSON?

Yes. Paste the whole envelope; namespace prefixes such as soap:Envelope are kept in key names. Navigate to the Body content for the actual payload.

Does XML to JSON keep the element order?

Order of different child elements is kept as object key order, but JSON consumers are not required to respect object key order. If order is meaningful, it is safer to model the data as an array.

Can I convert an RSS feed to JSON?

Yes. Paste the feed XML; each <item> becomes an element of the item array under rss.channel.

Related tools