XML Attributes to JSON
XML attributes are prefixed with @ in JSON. Elements with both attributes and text use #text for the content.
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 = `<book id="1" category="fiction">3 <title lang="en">The Great Gatsby</title>4 <price currency="USD">12.99</price>5</book>`;67// Browser8const parser = new DOMParser();9const doc = parser.parseFromString(xmlString, 'text/xml');1011// Node.js with xml2js (npm install xml2js)12const xml2js = require('xml2js');13const parser = new xml2js.Parser();14parser.parseString(xmlString, (err, result) => {15 console.log(JSON.stringify(result, null, 2));16});1718// Output:19// {20// "book": {21// "@id": "1",22// "@category": "fiction",23// "title": {...
More XML Examples
Simple XML to JSON
Basic XML element conversion to JSON object.
Nested XML to JSON
Deeply nested XML structures converted to nested JSON objects.
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.