Skip to content

XML to JSON Converter - Convert XML to JSON Online

Input XML
JSON Output

Convert XML to JSON

Paste XML on the left and the JSON equivalent appears on the right. The root element becomes the top-level key, child elements become nested objects, repeated siblings become arrays and attributes go under @attributes. The XML is parsed with your browser's built-in DOMParser, so nothing is uploaded, and a malformed document shows the parser's error instead of partial output.

Example

<order id="1042" currency="NZD">
  <customer>Ann</customer>
  <item sku="A1">Mug</item>
  <item sku="B7">Tea</item>
  <note><![CDATA[Leave at door & ring]]></note>
</order>

converts to:

{
  "order": {
    "@attributes": { "id": "1042", "currency": "NZD" },
    "customer": "Ann",
    "item": [
      { "@attributes": { "sku": "A1" }, "#text": "Mug" },
      { "@attributes": { "sku": "B7" }, "#text": "Tea" }
    ],
    "note": "Leave at door & ring"
  }
}

Note that id is the string "1042", not a number, and that with a single <item> the item key would hold an object instead of an array. (The real output puts each key on its own line.)

Where XML Still Turns Up

SOAP responses, RSS and Atom feeds, sitemaps, Maven pom.xml files, Android resources and many bank and government data exports are XML. Converting a sample to JSON is a quick way to see its structure before writing parsing code, or to query it with the JSON path finder. To go the other way, use the JSON to XML converter.

Related Tools

Frequently Asked Questions

How are XML attributes handled?
They are grouped under an "@attributes" key. <book id="1">Dune</book> becomes {"book": {"@attributes": {"id": "1"}, "#text": "Dune"}}. Text in an element that also has attributes or child elements goes under "#text"; an element with only text becomes a plain string.
Why is the same element sometimes an object and sometimes an array?
Repeated sibling elements with the same name become an array, but a single element stays an object. So an order with two <item> elements gives "item": [ ... ] while an order with one gives "item": { ... }. Code that reads the JSON should handle both shapes, or check the result for the case your data actually contains.
Are numbers and booleans converted?
No. XML has no data types, so every value is a string: <qty>3</qty> gives "qty": "3". Leading and trailing whitespace around text is trimmed.
Are XML namespaces preserved?
Prefixes stay part of the key, so <soap:Envelope> becomes "soap:Envelope". xmlns declarations appear under @attributes like any other attribute.
What about CDATA, comments and processing instructions?
CDATA content is treated as ordinary text and included in the string value. Comments, processing instructions and the <?xml ...?> declaration are dropped.