My Tool Studio
Developer Tools·2 min read

XML to JSON: Convert Feeds and Configs Cleanly

XML turns up in RSS feeds, SOAP responses, sitemaps and old config files, while your code usually wants JSON. The XML to JSON Converter parses the document and returns JSON that keeps attributes, nesting and repeated elements, updating as you type. Paste XML, drop or upload a .xml file, or load a feed from a URL. Everything runs in your browser.

.xml.jsonXML → JSON

How XML maps to JSON

Attributes, arrays and types.

By default each attribute becomes a key with an @_ prefix, so a book element with an id attribute gives an @_id key. You can pick @, _, $ or no prefix instead, or untick Keep attributes to drop them. When an element has both attributes and text, the text goes under a text key, #text by default. Repeated sibling elements become arrays, so two book elements inside a catalog become a book array.

With Detect numbers and booleans ticked, numbers and true or false values become real JSON types. Values with leading zeros, such as 00501 or an ISBN, stay as strings so the zeros survive. Output can be indented with 2 or 4 spaces or tabs, or minified.

Broken XML is reported, not guessed

A check before the conversion.

The document is checked for well-formedness first. If a tag is never closed, tags close in the wrong order, an attribute value lacks quotes or there is more than one root, the line is highlighted and you get its line and column instead of odd JSON. Go to line jumps there. That also makes the tool a quick way to confirm an XML file is well formed.

Details that trip people up

Worth knowing before you write code.

A few behaviours are easy to miss, and each has a setting:

  • By default a single child is not an array. One book gives an object and two give an array. Set Arrays to For every element, or list names such as book under Always arrays for, and the shape stays stable.
  • CDATA content becomes part of the element's text, with the markers removed. Tick Keep CDATA as #cdata to keep it under its own key.
  • Namespace prefixes stay in key names, such as dc:title, unless you tick Remove namespace prefixes. xmlns declarations appear as attributes.
  • The XML declaration is always dropped. Comments are dropped too, unless you tick Keep comments as #comment.

Going from JSON back to XML

The reverse direction.

The JSON to XML Converter handles the other way. Choose @ as the attribute prefix here, or the same prefix in both tools, and attributes come back as attributes. If your starting point is messy JSON rather than XML, the JSON Validator and JSON Formatter will get it into shape.

Try it now

Open XML to JSON Converter

The tool is one click away. No sign up, no upload, no payment.

Open XML to JSON Converter