About XML to JSON
Convert XML into JSON you can use in code. Attributes become keys starting with @, text next to attributes or child elements goes under #text, and elements that repeat become arrays. The XML is checked first, so a broken document gives an error with a line and column instead of half a result.
How to use XML to JSON
- Paste XML or open a file.
- Choose whether to include attributes and whether to trim spaces around text.
- Pick a JSON layout (2 spaces, 4 spaces, tab or minified).
- Copy the JSON or download converted.json.
Tips and good to know
- All values stay as text, so 5 and true are not turned into a number or boolean.
- Comments and processing instructions are dropped.
- A single child element is an object, but the same name twice becomes an array; code that reads the result should allow both.
Mapping XML to JSON
XML has attributes, repeated elements and mixed text that JSON doesn't model directly, so converters use conventions, such as a prefix for attributes and arrays for repeated tags. A single repeated element may come out as an object rather than an array, so check the structure before writing code against it.
Attributes and repeated elements
XML has features JSON lacks, so converters must make choices. Attributes are often stored with a prefix such as @id, text content next to attributes goes into a field like #text, and an element that appears once becomes an object while the same element repeated becomes an array. Check the shape of the result before writing code that depends on it.
Frequently asked questions
Why does the shape change when an element repeats?
XML has no array type, so the converter makes an array only when a name appears more than once under the same parent.
What about elements that mix text and tags?
The text is gathered under #text and a note appears, because JSON objects cannot keep the order of text between children.
Is XML to JSON free?
Yes. XML to JSON is free: no sign-up, no paid plan, no trial and no limit on how often you use it. It runs in your browser, and ToolzAura is paid for by ads, so every tool stays free.
Are my files uploaded?
No. This tool runs in your browser, so your input stays on your device.