How to use the Convert XML to JSON
- 1 Drop the XML file on the studio, or paste it, or try the example. Malformed XML is refused with the line and column.
- 2 Choose what to do with attributes and repeated elements, and whether numbers should become JSON numbers.
- 3 Read the notes for anything that was not kept.
- 4 Download or copy the JSON. Add “Convert JSON to XML” to test the way back.
XML and JSON do not map one to one
XML has attributes, element order, mixed text and elements, comments and namespaces. JSON has objects, lists and plain values. Every converter makes choices; the useful ones are the ones you can see. These are this step’s:
- An attribute becomes a key with a prefix (
@id); change the prefix or leave attributes out. - An element with only text becomes a string. With attributes as well, the text goes under
#text. - Repeated elements with the same name become a list. Choose to make a list of every child element, so the shape does not depend on whether there was one item or two.
- Values are text, because XML has no types. Turn on type conversion to get numbers and true/false; values such as
007stay text. - The root element is kept as the outer key unless you turn that off.
What is reported
Comments, processing instructions and the DOCTYPE are not part of the JSON; the notes count them. Elements that mix text and child elements keep their text under one key, in a fixed position. If same-named elements were not next to each other (a, b, a), the list order changes and you are told. Namespace prefixes are kept in the names as written.
Safe by construction
The XML reader is strict, as XML 1.0 requires, and it never expands entities defined in a DOCTYPE or reads external files, so a hostile document cannot cause harm.
Limits
Format and check XML without converting by choosing that step. Convert in the other direction with “Convert JSON to XML”, which sanitises names that XML does not allow.
Frequently asked questions
Why are all values strings?
XML text has no type. Turn on “Turn numbers and true/false into JSON types” if you want numbers and booleans; identifiers like 007 are kept as text.
Does the conversion lose anything?
Comments, processing instructions, the DOCTYPE and the order of different element names can be lost. The notes list exactly what applied to your file.
What happens to attributes?
They become keys starting with @ by default. You can choose another prefix or leave attributes out.
Last updated: