"category": "format-converter",
XML to JSON Converter
"tldr": Paste XML and get clean typed JSON - repeated elements become arrays, numeric and boolean text is converted automatically.
Convert XML documents into clean JSON. Paste a SOAP response, RSS feed, sitemap, or legacy config file and get a JSON object that mirrors the element structure - repeated elements become arrays, text content becomes values, and numeric or boolean text is typed automatically.
The converter uses your browser’s native XML parser, so malformed documents are caught with a clear error message instead of producing silently broken JSON. As with every JSON Console tool, your data stays on your machine.
How to convert XML to JSON
- 1Paste your XML into the input panel - the document must be well-formed.
- 2Elements become JSON keys; repeated sibling elements with the same tag are merged into an array.
- 3Text content that looks like a number or boolean is converted to the matching JSON type.
- 4Copy the JSON output or download it as a .json file.
Convert XML to JSON in code
import json
import xmltodict # pip install xmltodict
with open("data.xml") as f:
data = xmltodict.parse(f.read())
print(json.dumps(data, indent=2))const doc = new DOMParser().parseFromString(xmlString, "application/xml");
function toJson(node) {
const children = [...node.children];
if (!children.length) return node.textContent;
const obj = {};
for (const child of children) {
const value = toJson(child);
obj[child.tagName] = child.tagName in obj
? [].concat(obj[child.tagName], value)
: value;
}
return obj;
}Frequently asked questions
How does the converter decide what becomes an array?
When two or more sibling elements share the same tag name, they are grouped into a JSON array. A single occurrence stays an object or value. If your schema allows repeats but a sample document has only one, normalize that field to an array in your consuming code.
What happens to XML attributes?
This converter focuses on element structure and text content, which covers most real-world feeds and API responses. Attribute-heavy documents may need a library with an explicit attribute convention (such as xmltodict in Python, which prefixes attributes with @).
Why does my SOAP envelope produce deeply nested JSON?
SOAP wraps the payload in Envelope and Body elements, and the converter faithfully mirrors that nesting. Drill into result.Envelope.Body (names vary by service) to reach the actual data, or strip the envelope before converting.
Is namespace information preserved?
Element names keep their prefixes as written (like soap:Body becomes the key "soap:Body"), but namespace URIs themselves are not carried over since JSON has no namespace concept.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →