XML to JSON
Convert XML to JSON: attributes become @keys, repeated elements become arrays, with options for text and types.
About XML to JSON
XML to JSON converts XML feeds and documents into JSON for modern APIs and scripts. Attributes become keys starting with @, text is kept, and repeated elements become arrays.
The array option
Turn on always-array for elements that can repeat. Then an element that appears once in one file and three times in another is always an array, and your code does not break.
Types and empty elements
Convert numbers and true/false into real JSON types, and turn empty elements into null.
Namespaces
Skip xmlns declarations you do not need in the output.
Good to know
XML and JSON are different models, so comments and the exact order of mixed content may not be kept.
Private
Your data is processed in your browser. Nothing is uploaded.
XML vs JSON
XML uses opening and closing tags and can carry attributes, while JSON uses braces, arrays and key-value pairs. JSON is shorter and is the usual choice for web APIs.
How to use XML to JSON
- Paste your XML or open a file.
- Set the attribute prefix, text key and indent.
- Tick the array, type and whitespace options you need.
- Press Convert to JSON, then copy or download it.
- Check the JSON with the JSON Formatter, looking at one repeated element to confirm it became an array.
Help & FAQ
How are attributes and text mapped?
Attributes become keys with a prefix (default @). If an element has both text and attributes or children, its text is stored under #text. Repeated sibling elements become an array.
What is lost in conversion?
Comments, processing instructions, the XML declaration, DOCTYPE and the ordering between different sibling element names are not kept in JSON.
One item versus many?
A single child is an object and several are an array unless you tick "always arrays", which gives a stable shape.
Why did a single element become an object instead of an array?
Without the 'always arrays' option, one child becomes an object and several become an array. Tick the option to get an array every time.
Can we convert JSON back to XML?
This tool converts only from XML to JSON. For other conversions between data formats, see the JSON to YAML and YAML to JSON tools.
What happens to XML attributes?
Each attribute becomes a key with the prefix you choose (by default @), next to the element's own child elements or text.
Is our XML uploaded?
The conversion runs in your browser, so the document is not sent to a server for the conversion itself.