XML to JSON Converter

← All tools

Convert XML to JSON, or JSON back to XML. The mapping for attributes, repeated elements, and text is the one listed below.

The document never leaves the browser. Nothing is uploaded.

Open file…

Options

Direction, minify, and the declaration are stored in the URL. The document stays on this page. JSON to XML uses to=xml. Minify uses indent=0. A dropped declaration uses decl=0.

Not converted

Result

The preview is cut at 200,000 characters. Copy and Download include everything.

About this tool

The root element is the one key of the JSON object. An attribute is a key that starts with @. An element that holds only text becomes a string, and that string is not trimmed. An element with attributes and text keeps the text in #text. An empty element becomes an empty string. An empty element with attributes becomes an object of those attributes.

Whitespace between child elements is dropped. If an element mixes text with child elements, the text is collected into #text and that text is not ordered against the children. One child with a given name stays an object. Two or more with the same name become an array, in the order they appear. A list of one will come back as an object, so it does not round-trip as an array. If the same name shows up again after a different element, the page groups them and says that their order against the other elements is not kept.

Comments and processing instructions are dropped, and the page counts them. CDATA is text. A DOCTYPE is rejected. This page does not read a DTD, and it does not fetch entities. The only entities it expands areamp, lt, gt, quot,apos, and numeric character references. Tag names are kept as written, prefixes included. xmlns stays an attribute. The XML declaration is not part of the JSON. The page notes its version and encoding. Numbers are not inferred, so a year stays a string.

The other direction wants one root object with one element key. Arrays repeat that element. A JSON number or boolean becomes text, and the page says so. null becomes an empty element. An empty array writes no elements. An integer outsideNumber.MAX_SAFE_INTEGER was already rounded byJSON.parse, and the page says that too. The declaration line is version="1.0" and encoding="UTF-8"unless you turn it off. Files up to 1 MB open in the page.

Read more

Free books, courses, and software

Get my programming books, course editions, and complete software.

Get the download library →