TXT · Text & Data tools

XML to JSON Converter

Input · XML
Output · JSON
0 Bin0 Bout0lines in0keysEmptyXML
Go to the full Data Format Converter

XML to JSON

Convert an XML document into a JSON value. Paste XML on the left; the JSON output builds on the right as you type.

<order id="1042">
  <status>shipped</status>
  <items>pen</items>
  <items>notebook</items>
</order>

becomes

{
  "order": {
    "@_id": "1042",
    "status": "shipped",
    "items": ["pen", "notebook"]
  }
}

The root element’s tag name becomes the single top-level key. id="1042" becomes @_id because it’s an attribute, not a child element. The two <items> elements share a name, so they collapse into one items array rather than overwriting each other.

Attributes and text together

An element that mixes attributes with text content, like <price currency="usd">19.99</price>, needs both an @_currency key and a #text key: { "price": { "@_currency": "usd", "#text": "19.99" } }. An element with only text and no attributes, like <name>Ada</name>, skips the wrapper entirely and becomes "name": "Ada".

Values stay text

XML doesn’t distinguish a number from a string; <count>3</count> and <count>three</count> are both just element text. This converter keeps every XML value as a JSON string rather than guessing which ones should become numbers or booleans, so a downstream JSON.parse on a numeric field needs an explicit conversion.

Malformed XML

An unclosed tag, a stray & that isn’t part of a named entity like &amp;, or more than one element at the root all fail to parse. The input pane’s error footer reports the line and column the parser stopped at, taken directly from the browser’s XML parser.

Frequently Asked Questions

Each attribute becomes a key named @_ followed by the attribute name, sitting next to the element's other keys. <item id="7"> becomes { "item": { "@_id": "7" } }.

It becomes a key named #text. An element with only text and no attributes or children collapses straight to that text as a plain JSON string, with no wrapper object.

An element name that repeats under the same parent becomes a JSON array of its values. An element that appears once stays a single value, so the array shape depends on the input, not on a fixed schema.

The input pane reports the parser's line and column for malformed XML, most often an unclosed tag, an unescaped & in text, or more than one root element. Fix the reported line and the output updates automatically.

No. Namespace-prefixed elements and attributes, like ns:id, keep their prefix as part of the JSON key rather than resolving to a full namespace URI.

Jump straight to a conversion

Full Data Format Converter tool

Explore Our Tools

Browse all tools