XML to JSON Converter Online - Free & Private
Paste XML or drop a file and get JSON you can work with in JavaScript, Python or any API. Attributes are kept with an @ prefix, repeated elements become arrays, and numbers and booleans can be converted to real values.
How to convert XML to JSON
- Paste XML into the left editor, or open or drop an .xml file, an RSS or Atom feed, a sitemap or a SOAP response.
- JSON appears on the right. If the XML is not well formed, for example a tag is never closed, the error and its line number are shown.
- Explore the result in tree view, copy it, or download it as a .json file.
How XML maps to JSON
- The root element becomes the single top-level key.
- Child elements become keys. An element that appears more than once becomes an array.
- Attributes become keys with a prefix,
@by default, so<book id="bk101">gives{"@id": "bk101"}. - An element with only text becomes a plain value. An element with attributes or children as well as text keeps the text under
#text. - CDATA sections are read as text, and comments and processing instructions are dropped.
- Namespace prefixes are kept in the key names, for example
soap:Body.
Options
- Keep attributes: turn off to ignore attributes and keep only element content.
- Attribute prefix: change
@to_,$or nothing at all, to match what your code expects. - Detect numbers: turn
44.95,trueandfalseinto numbers and booleans. Turn it off to keep every value as a string. - Always arrays: wrap every child element in an array, even when it appears once. This gives the same shape for a feed with one item as for a feed with fifty, which makes the JSON much easier to loop over in code.
- Indent: spaces per level in the JSON.
Example
<catalog> <book id="bk101"><price>44.95</price></book> <book id="bk102"><price>5.95</price></book> </catalog>
becomes {"catalog":{"book":[{"@id":"bk101","price":44.95},{"@id":"bk102","price":5.95}]}}.
To go back, use the JSON to XML converter.
Private by design
The XML is parsed by your browser's own XML parser. Nothing is uploaded, and external entities are never fetched.