Two formats, one mapping
XML has attributes, repeated elements, text and order; JSON has objects, arrays and values. There is no single official way to translate between them, so this converter uses one clear convention and applies it in both directions. Paste XML to get JSON, switch direction to turn JSON back into XML.
Convert in five steps
- Choose XML → JSON or JSON → XML.
- Paste your data into the left box. An example library catalog is there to show the mapping.
- Set the options: indentation, whether attributes are kept, and whether numbers and true/false are converted from text.
- Read the result on the right. If the input is invalid, the message names the problem with the line and column.
- Copy the result or download it as a file.
The mapping rules
- An attribute becomes a key that starts with
@:<book id="1">gives"@id": "1". - An element with only text becomes a string. When it also has attributes or children, the text goes into
"#text". - Elements that repeat under the same parent become an array. A list with only one entry stays a single object, so check such cases.
- An empty element becomes an empty string in JSON, and
nullin JSON becomes an empty element in XML. - CDATA is read as text. Comments and processing instructions are dropped, because JSON has no place for them.
What does not survive the trip
JSON objects have no guaranteed order of attributes and elements are grouped by name, so an XML document that interleaves different elements loses that interleaving. Text mixed between elements, as in a paragraph with a bold word, is joined into one #text value. Data-style XML such as feeds, configuration and API responses converts cleanly; document-style XML such as articles does not.
Nothing is uploaded
The conversion runs in your browser. Feeds, exports and responses you paste are not sent anywhere.