Nested XML to JSON
Nested XML elements become nested JSON objects. Multiple elements with the same name become arrays.
Switch tool:
Examples:
JSON output will appear here...
💡 Paste your XML and it converts to JSON automatically. Attributes are prefixed with @ and text content uses #text.
Code Examples
Here's how to achieve this in different programming languages:
1// Using DOMParser (browser) or xml2js (Node.js)2const xmlString = `<company>3 <department>4 <name>Engineering</name>5 <employees>6 <employee>John</employee>7 <employee>Jane</employee>8 </employees>9 </department>10</company>`;1112// Browser13const parser = new DOMParser();14const doc = parser.parseFromString(xmlString, 'text/xml');1516// Node.js with xml2js (npm install xml2js)17const xml2js = require('xml2js');18const parser = new xml2js.Parser();19parser.parseString(xmlString, (err, result) => {20 console.log(JSON.stringify(result, null, 2));21});2223// Output:24// {25// "company": {26// "department": {27// "name": "Engineering",28// "employees": {...
More XML Examples
Simple XML to JSON
Basic XML element conversion to JSON object.
XML Attributes to JSON
XML elements with attributes converted to JSON with @ prefixed properties.
RSS Feed to JSON
Transform RSS feed XML into JSON format for web apps.
SOAP Response to JSON
Transform SOAP web service responses to JSON format.
XML Config to JSON
Transform XML configuration files to JSON format.