🛠️DevTools

Simple XML to JSON

Simple XML elements are converted to JSON properties. Boolean and number values are automatically parsed.

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 = `<person>
3 <name>John Doe</name>
4 <age>30</age>
5 <active>true</active>
6</person>`;
7
8// Browser
9const parser = new DOMParser();
10const doc = parser.parseFromString(xmlString, 'text/xml');
11
12// Node.js with xml2js (npm install xml2js)
13const xml2js = require('xml2js');
14const parser = new xml2js.Parser();
15parser.parseString(xmlString, (err, result) => {
16 console.log(JSON.stringify(result, null, 2));
17});
18
19// Output:
20// {
21// "person": {
22// "name": "John Doe",
23// "age": 30,
24// "active": true...

More XML Examples

Related XML Tools

📚 Learn More