XML Online Viewer is a fast, 100% browser-based XML tool for pretty-printing XML tags, stripping whitespace, and parsing XML nodes into clean JSON data structures with DOMParser validation.
Free Online XML Viewer & XML to JSON Converter
Cleanly format XML tag elements, compress XML code, or parse XML into structured JSON objects.
Pretty-Print XML Tags
Indent nested XML tag hierarchies with clean spacing for easy reading and debugging.
XML to JSON Converter
Parse XML elements and attributes into standard JSON format with a single click (Alt+6).
XML Minifier
Strip unnecessary whitespace and newline breaks to minimize XML payload size.
Developer Tips: XML to JSON in JavaScript
Need to convert XML to JSON programmatically? The browser's native DOMParser API lets you parse XML strings without any library:
// Convert XML to JSON in the browser (JavaScript)
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlString, "text/xml");
// Walk the DOM tree and build a JSON object
function xmlToJson(node) {
const obj = {};
if (node.attributes) {
for (const attr of node.attributes) {
obj["@" + attr.name] = attr.value;
}
}
for (const child of node.childNodes) {
if (child.nodeType === 3) obj["#text"] = child.textContent.trim();
else if (child.nodeType === 1) obj[child.nodeName] = xmlToJson(child);
}
return obj;
}
const json = xmlToJson(xmlDoc.documentElement);
console.log(JSON.stringify(json, null, 2));
Node.js developers: For server-side XML-to-JSON conversion, use packages like xml2js or fast-xml-parser. Alternatively, run browser-compatible XML parsing in Node.js 18+ using the built-in DOMParser from linkedom or jsdom.