XML to JSON Converter

Paste your XML below to convert it to JSON.

How it is calculated

The tool parses the XML you paste and rebuilds its tree as indented JSON. The root element's name is reported separately and is not a key in the JSON, which starts with the root's contents. Attributes go into an "@attributes" object. An element with children becomes an object keyed by child name. When the same name repeats, the values become an array, and repeats are grouped together even if other elements sit between them. An element with only text becomes a string (leaving numbers and true/false as strings), and an empty element becomes []. Text mixed with attributes or children goes under "#text". CDATA is treated as text and comments are dropped. Namespaced names keep their prefix. The node count is the number of elements. Invalid XML gives no result.

Worked example

Paste <order id="17"><item>Pen</item><item>Ink</item></order>. The root is order, and the tool counts one order element and two item elements, so the node count is 3. The attribute id="17" becomes "@attributes": {"id": "17"}. The two item elements share a name, so they become the array "item": ["Pen", "Ink"]. The order tag itself is not a key. With only one item, the same field would be a plain string "item": "Pen" instead of an array.

Try this example →

Common mistakes

  • Expecting the root tag as the top-level key. The output starts with the root's contents; the root name is only shown in the root field, so add it back if the JSON consumer needs it.
  • Assuming a repeated element is always an array. One <item> becomes a string or object, two or more become an array, so code reading the result must handle both.
  • Expecting numbers and booleans. Every value comes out as a string, so <qty>007</qty> becomes "007", with its leading zeros kept.
  • Relying on the original order of mixed elements. Same-named siblings are grouped, so b, c, b comes out as b: [first, second], c.
  • Pasting broken XML: an unclosed tag, an unescaped & or two root elements. The parser gives no result rather than a partial one, so fix the markup first.

About this calculator

XML and JSON are both structured, human-readable data formats, but they organize information differently — XML uses nested tags and attributes, while JSON uses nested objects, arrays, and key-value pairs — so translating between them by hand is tedious and error-prone. This converter parses any XML document, walks its element tree, and rebuilds it as clean, pretty-printed JSON, reporting the root element name and an approximate node count along the way.

The conversion is a routine step for developers integrating legacy or third-party systems — many older APIs, RSS/Atom feeds, SOAP services, and enterprise systems still speak XML, while most modern web and mobile apps consume JSON — so converting a sample response is often the fastest way to sketch out a JSON schema, test a new endpoint, or feed XML data into a JavaScript front end.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Because repeated tag names are grouped into one array, the order in which different tags were interleaved is not kept. That is harmless for records and feeds, but documents where sequence matters, such as marked-up text or step lists mixing tag types, will not round-trip back to the original XML. Also remember that every leaf value stays a string, so cast numbers and booleans in your own code. What kind of XML are you converting, a feed, a config file or an API response?

Popular calculators

All Calculators