> xml | json | convert <
// Convert between XML and JSON data formats instantly
XML↔JSON Conversion
Convert XML to JSON and JSON back to XML with a single click. Full bidirectional support.
Syntax Check
Automatic validation of XML and JSON syntax. Clear error messages for malformed input.
Attribute Support
Handles XML attributes, nested elements, CDATA sections, and repeated elements as arrays.
// ABOUT XML TO JSON CONVERSION
How It Works:
XML is parsed using the browser's native DOMParser API and recursively traversed to build a JSON object. XML attributes are prefixed with '@', text content uses '#text' when mixed with child elements, and repeated sibling elements are automatically grouped into arrays. JSON to XML reversal follows the same conventions.
Example:
<book id="1"><title>Hello</title></book> → {"book":{"@id":"1","title":"Hello"}}
Common Use Cases:
- >Convert SOAP/XML API responses to JSON
- >Migrate XML configuration files to JSON
- >Transform XML data feeds for web applications
- >Convert JSON payloads to XML for legacy systems
- >Parse and inspect complex XML structures
>> frequently asked questions
Q: What is the difference between XML and JSON?
A: XML (eXtensible Markup Language) uses tags and attributes to structure data hierarchically, following W3C standards. JSON (JavaScript Object Notation) uses key-value pairs defined by RFC 8259. JSON is more compact and natively supported in JavaScript, while XML supports attributes, namespaces, and schemas.
Q: How are XML attributes mapped to JSON?
A: XML attributes are converted to JSON properties with an '@' prefix. For example, <item id="1"> becomes {"@id": "1"} in the JSON output. This convention distinguishes attributes from child elements.
Q: How are nested and repeated elements handled?
A: Nested XML elements become nested JSON objects. When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array. For example, multiple <item> elements become an array under the "item" key.
Q: How is CDATA handled?
A: CDATA sections in XML are treated as text content. The CDATA wrapper is removed and the content is included as a regular string value in the JSON output.
Q: Are XML namespaces supported?
A: Namespace prefixes are preserved in element and attribute names as-is. For example, <ns:element> becomes a "ns:element" key in JSON. The namespace declarations (xmlns attributes) are also preserved with the '@' prefix convention.