How to use it
- Choose an XML file, drop it on the box, or paste XML into the text field; the result appears at once.
- Check the options: whether repeated elements are arrays everywhere, which elements should always be arrays, and the indentation.
- Look at the preview, then download the .json file or copy the result.
- If the XML has an error, the message shows the line and the column. Fix it: pasted text is converted again as you type.
Rules and limits
XML and JSON mapping
- Each element becomes a key with the element’s name. Namespace prefixes stay part of the name:
soap:Body. - Attributes become keys with an “@” in front:
id="7"becomes"@id": "7". Namespace declarations are kept the same way, as"@xmlns:soap". - An element with only text becomes that text. If it also has attributes or child elements, its text goes under
"#text":<price currency="EUR">12.50</price>becomes{"price": {"@currency": "EUR", "#text": "12.50"}}. - Elements that repeat under the same parent become an array, in document order. Interleaved names are grouped, so the order between different names is not kept.
- CDATA sections become ordinary text. Comments, processing instructions and the DOCTYPE are dropped. Entities defined only in an external DTD, such as
in XHTML, are kept as written, with a note. - An empty element such as
<note/>becomes"". Whitespace between elements is dropped and text is trimmed, except insidexml:space="preserve". - All values stay strings, because XML has no data types:
"00123"keeps its leading zeros.
Questions and answers
Why are all numbers in quotes?
XML has no data types, so every value is converted as a string. Turning "00123" or "1e5" into numbers would change the data. Convert the types in your own code, where you know which fields are numbers.
When does an element become an array?
When it appears more than once under the same parent. With “Repeated elements as arrays everywhere” on (the default), an element that repeats anywhere becomes an array at the same path in every record, so all records have the same shape. For elements that never repeat in this file, enter their names under “Always arrays”.
Can I convert the JSON back to XML?
Yes, with JSON to XML, which uses the same mapping: namespace prefixes and declarations are kept as keys, so the namespaces come back. Comments, processing instructions, CDATA sections and the order between different element names are not kept.