🛠️DevTools

XML Config to JSON

XML configuration files convert to JSON for use with modern frameworks and JavaScript applications.

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 = `<config>
3 <database>
4 <host>localhost</host>
5 <port>5432</port>
6 <name>myapp</name>
7 </database>
8 <cache enabled="true">
9 <ttl>3600</ttl>
10 </cache>
11</config>`;
12
13// Browser
14const parser = new DOMParser();
15const doc = parser.parseFromString(xmlString, 'text/xml');
16
17// Node.js with xml2js (npm install xml2js)
18const xml2js = require('xml2js');
19const parser = new xml2js.Parser();
20parser.parseString(xmlString, (err, result) => {
21 console.log(JSON.stringify(result, null, 2));
22});
23
24// Output:
25// {
26// "config": {
27// "database": {
28// "host": "localhost",
29// "port": 5432,...

More XML Examples

Related XML Tools

📚 Learn More