XML to JSON Converter

The XML to JSON Converter transforms XML data into JSON format. XML is common in SOAP APIs, RSS feeds, configuration files, and enterprise systems, while JSON is preferred by modern web applications and REST APIs. This converter parses XML elements, attributes, text content, and namespaces, converting them into a clean JSON structure. It is ideal for modernizing legacy integrations, migrating data from XML-based systems, and consuming SOAP or RSS feeds in JavaScript applications.

Formula

Conversion rules:
- XML element → JSON object key
- XML text content → JSON value
- XML attributes → JSON keys with @ prefix
- Repeated elements → JSON array
- Nested elements → Nested JSON object

XML declaration is removed

Example

Input XML: <user> <name>Alice</name> <age>30</age> </user> Output JSON: { "user": { "name": "Alice", "age": 30 } }

How to Use

  1. Paste your XML data into the input field
  2. Configure namespace and attribute handling if needed
  3. Click convert to generate JSON
  4. Review the JSON structure
  5. Copy or download the JSON output

Frequently Asked Questions

How are XML attributes converted?

XML attributes are converted to JSON keys with an @ prefix by convention. For example, <user id="123"> becomes {"user": {"@id": "123"}}. This distinguishes attributes from child elements in the JSON output.

How are XML namespaces handled?

Namespaces are preserved as part of the element name or stored in a separate @xmlns object. You can configure whether to strip namespaces or keep them. Most modern use cases strip namespaces for cleaner JSON.

What happens with mixed content XML?

Mixed content (text and elements interleaved) is challenging. The converter typically places text in a #text key and elements as separate keys. This is a known limitation of XML-to-JSON conversion.

Can I convert large XML files?

For files under 10MB, the browser handles it well. For larger files, use a streaming parser like sax-js or Python's lxml. This online tool is best for moderate-sized XML documents.

Is the JSON output valid?

Yes, the output is valid JSON that can be parsed by any JSON parser. However, the structure may vary depending on conversion options. Always review the output to ensure it meets your application's expectations.