Monitoring
Solutions
Resources
Free Tools
Pricing
Free Tools / Converters / XML to JSON Converter

XML to JSON Converter

Paste XML and get JSON you can work with in code. Attributes are kept, repeated elements become arrays, and a malformed document is reported instead of half-converted.

Runs entirely in your browser — nothing you enter here is sent to a server.

How XML is turned into JSON

XML has features JSON does not — attributes, mixed text and elements, repeated siblings — so a converter needs rules for each. The rules here follow the widely used convention that keeps the result predictable and lets it be converted back.

Elements become keys

An element with only text becomes a key with a string value. An element with children becomes an object. An empty element becomes null.

Attributes get a prefix

<category domain="severity"> yields "@domain": "severity". The prefix keeps attributes apart from child elements of the same name.

Text next to attributes

When an element has attributes and text, the text goes under "#text", since an object cannot also be a string.

Repeated elements become arrays

Two or more siblings with the same name are collected into an array, in document order.

Two things to watch for

A list with one item is not an array. XML does not say whether an element may repeat, so a feed with a single <item> gives an object where a feed with two gives an array. Code that reads the JSON should accept both — or normalise the value to an array first. Only a schema can settle it for certain.

Everything is a string unless you say otherwise. XML has no number or boolean type. By default values are kept as text, so "007" and "1.10" survive intact. Tick "detect numbers, booleans and null" if you want 42 and true converted.

Frequently asked questions

How are XML attributes represented in JSON?

As keys with a prefix, by default @. An attribute id="7" becomes "@id": "7" inside the object for that element. The prefix can be changed to _ or -.

Why is a single child element not converted to an array?

XML gives no indication that an element may repeat. Without a schema, one occurrence is converted as a single value and several as an array.

What happens to CDATA sections and comments?

CDATA content is treated as ordinary text. Comments and processing instructions are dropped, since JSON has no equivalent.

Are namespaces preserved?

Prefixed names such as soap:Envelope are kept as they are, and xmlns declarations appear as attributes. The converter does not resolve prefixes to namespace URIs.

Related free tools

A calculator answers once. Monitoring answers every minute.

Upzilla checks your sites, servers and APIs around the clock and alerts you the moment something breaks. 10 monitors free, no card required.

Start monitoring free →