Convert XML data to JSON format
Convert XML to JSON format instantly with our free online XML to JSON converter. This tool helps developers transform XML data into JSON structure for modern APIs and web applications. Simply paste your XML and get JSON output in real-time.
Convert XML to JSON format. This tool parses XML and converts it to a JavaScript-friendly JSON structure. XML attributes are preserved with the "@_" prefix.
Note: Attributes in XML are converted to properties prefixed with "@_".
XML to JSON conversion transforms XML documents into JSON format for use in modern web applications and APIs. This enables legacy XML data and SOAP services to integrate with JSON-based systems, JavaScript applications, and REST APIs.
The converter parses XML elements, attributes, and text content into a JSON structure. Elements become object keys, attributes typically get an @ prefix, text content becomes values. Array detection handles repeated elements. The mapping conventions vary by implementation.
XML-to-JSON mapping challenges: attributes vs elements (use @attr convention), mixed content (text + elements), repeated elements (detect as arrays), namespaces (preserve or strip), CDATA sections, and empty elements. No universal standard exists - conventions like BadgerFish, Parker, or custom mappings are used.
Convert SOAP/XML responses for modern JSON-based apps.
Transform SOAP response to JSON for React frontendConvert XML data exports to JSON for new systems.
Build JSON APIs that wrap XML backends.
Migrate XML configs to JSON format.
const xml2js = require('xml2js');
const xml = `
<user id="123">
<name>John Doe</name>
<email>john@example.com</email>
</user>
`;
xml2js.parseString(xml, {
explicitArray: false,
mergeAttrs: true
}, (err, result) => {
console.log(JSON.stringify(result, null, 2));
});
// {"user":{"id":"123","name":"John Doe","email":"john@example.com"}}xml2js is popular for Node.js. explicitArray:false prevents single elements becoming arrays.
import xmltodict
import json
xml = """
<user id="123">
<name>John Doe</name>
<email>john@example.com</email>
</user>
"""
data = xmltodict.parse(xml)
json_str = json.dumps(data, indent=2)
# Attributes get @ prefix: {"user": {"@id": "123", "name": "John Doe"}}xmltodict uses @ prefix for attributes by default. It's simple and handles most common cases.
Use XML to JSON when integrating legacy XML systems with modern apps, converting SOAP responses for REST clients, or migrating XML data to JSON-based storage.
Common conventions: @attributeName as a property, _attributes object containing all attributes, or attributes merged with elements. Choose based on your data needs and avoid naming conflicts.