Free XML To JSON Online

Convert XML to pretty-printed JSON. Attributes become @keys, repeated tags become arrays, CDATA is read as text. Free, no sign-up.

No login. Files processed for your request and discarded. Free to use. Files processed & discarded →

Compress PDF — it's free or choose from 130+ tools

130+ Free Tools
— Files Processed
— Happy Visitors
— Pages Explored
0 Files Stored

XML to JSON: Convert XML Elements and Attributes to JSON

Part of Text tools: See all Text tools.

What is XML To JSON?

XML to JSON Converter turns an XML document into pretty-printed JSON. Child elements become keys, repeated sibling elements become an array, attributes become keys starting with @, and text that sits next to attributes or child elements goes under #text. CDATA is read as plain text. The conversion runs on our server for your request; the text is not saved.

How to use XML To JSON

  1. Paste your XML into the input box.
  2. Click Convert.
  3. If the XML is malformed, the error message gives the line and column of the problem; fix it and convert again.
  4. Copy the JSON from the output box.

Why use this tool?

When an older system, RSS feed or SOAP service hands you XML but your code or spreadsheet workflow expects JSON, a quick conversion saves writing a parser. Attributes are kept rather than silently dropped, so ids, units and types in the XML stay visible in the JSON.

XML To JSON — In-Depth Guide

The converter uses the common xmltodict-style mapping. The root element becomes the single top-level key, child elements become nested keys, attributes become @name keys, and text next to attributes or children goes under #text. An element with only text becomes a plain string, and an empty element becomes an empty string.

The trickiest part of XML to JSON is arrays. XML has no list syntax, only repeated elements, so a converter can only tell something is a list when it sees more than one. If your feed sometimes has one <item> and sometimes several, normalise it in code (for example, wrap a single object in a list) before looping over it.

Everything in the output is a string. That is not a bug in the converter; XML stores all values as text and only a schema says that a field is a number or a date. Parse the fields you need with your language's number and date functions after converting.

Before converting a large or important file, check that it is well-formed. A missing closing tag, an unescaped & or two root elements will stop the conversion, and the error message points to the line and column so you can fix it. The XML Formatter on this site can help you read a long document first.

Frequently asked questions

How are XML attributes represented in JSON?
Each attribute becomes a key prefixed with @. <item id="5">Pen</item> becomes {"item": {"@id": "5", "#text": "Pen"}}.
How are repeated elements handled?
Siblings with the same name are grouped into an array, so two <tag> elements give "tag": ["x", "y"]. A single <tag> stays a plain value, which means the same element can be a string in one document and an array in another; handle both in your code.
Does it handle CDATA sections?
Yes. CDATA content is read as ordinary text, so <a><![CDATA[1 < 2]]></a> becomes {"a": "1 < 2"}.
What about namespaces?
Namespace prefixes and URIs are removed and only the local name is kept, so <ns:price> becomes "price". If two namespaces use the same local name in one element, their values end up in the same key or array.
What about mixed content like <p>Hello <b>world</b>!</p>?
Child elements become keys and the surrounding text pieces are joined into #text, so the exact position of the text between tags is not kept. Use a dedicated HTML or XML library if word order inside mixed content matters.
Are numbers and booleans converted?
No. Every value comes out as a string, because XML has no data types without a schema. Convert "42" or "true" to numbers or booleans in your own code if you need to.
Is my data stored?
No. The text is sent over HTTPS, converted on our server for that request and not saved. Avoid pasting confidential data into any online tool.

Also try

Related tools that work well with this one: