How to use the XML to JSON
- Paste XML or open an
.xmlfile. - Choose how attributes, types and empty elements are handled.
- List element names that should always be arrays, even when they appear once.
- Copy or download the JSON.
How XML maps to JSON
| XML | JSON |
|---|---|
<name>Ada</name> | "name": "Ada" |
<price currency="USD">9.5</price> | "price": {"@currency": "USD", "#text": 9.5} |
Repeated <tag> elements | "tag": ["a", "b"] |
<![CDATA[ … ]]> | Plain string |
<empty/> | "" or null |
The array problem
XML has no arrays, only repeated elements. A converter cannot know that <item> is a list when it appears only once, so the JSON shape changes with the data: one item gives an object, two give an array. That breaks code that expects a list. List such element names under Always arrays for to get consistent output.
Types
All XML content is text. With Detect numbers & booleans, values like 42, 9.5 and true become JSON numbers and booleans. Long numbers (more than 15 digits) and values with leading zeros stay strings to avoid precision loss.
Validation
The XML is parsed with your browser’s XML parser, so malformed input — an unclosed tag or unescaped & — is reported instead of producing broken JSON. Namespaced names (g:price) keep their prefix. Explore the result with the JSON viewer, or convert back with JSON to XML.
Tools that pair well with the XML to JSON
- XML Formatter — Turn minified or messy XML into clean, indented markup and check that it is well-formed — for feeds, sitemaps, SOAP messages, configs and SVG.
- YAML to JSON — Paste YAML — a Compose file, Kubernetes manifest or CI config — and get formatted JSON.
- JSON to YAML — Paste JSON and get clean YAML for Kubernetes manifests, Docker Compose, GitHub Actions or any config file.
- JSON to CSV — Turn a JSON array into a spreadsheet-ready CSV.
Frequently asked questions
Why is a single element an object but several are an array?
What happens to attributes?
Are namespaces supported?
atom:link are kept as keys; namespace declarations appear as @xmlns attributes.