About This Tool
Convert any XML document to clean, well-formatted JSON with a single click. XML and JSON are the two most common data interchange formats used across APIs, configuration files, and data feeds. While XML remains widespread in enterprise systems, SOAP services, and legacy integrations, JSON has become the default for modern REST APIs and web applications. Moving data between these two formats is a frequent task for developers, data analysts, and system administrators who work with multiple systems that speak different data languages. This free XML to JSON converter parses your XML input, preserves the full element hierarchy including attributes, and produces properly indented JSON output ready for use in any application. It handles nested elements at any depth, repeated sibling tags that automatically become JSON arrays, XML attributes stored under a configurable prefix, mixed text content alongside child elements, and self-closing empty tags. Choose your preferred indentation (two or four spaces) and attribute prefix format (@attributes or _attributes) to match your project conventions. Paste your XML, click convert, and copy the formatted JSON result with one click. No signup is required and no data limits are enforced. Your data stays completely private and nothing is stored or shared. The tool works instantly for documents of any reasonable size, making it ideal for quick conversions during development, debugging API responses, or preparing data for import into JSON-based systems.
How XML to JSON Conversion Works
XML and JSON represent data in fundamentally different ways. XML uses opening and closing tags with optional attributes, while JSON uses key-value pairs with nested objects and arrays. The conversion process maps XML structures to their JSON equivalents using these rules:
- Elements become keys: Each XML element tag name becomes a JSON key, and its content becomes the value
- Attributes become nested objects: XML attributes are grouped under a configurable prefix key (such as @attributes) to distinguish them from child elements
- Repeated elements become arrays: When multiple sibling elements share the same tag name, they are automatically grouped into a JSON array
- Text-only elements become strings: An element with no children and no attributes is converted to a simple string value
- Mixed content is preserved: Elements containing both attributes and text content store the text under a #text key
For example, the XML element <book category="fiction">The Great Gatsby</book> converts to {"book": {"@attributes": {"category": "fiction"}, "#text": "The Great Gatsby"}}. This mapping ensures no information is lost during conversion.
Common Use Cases
XML to JSON conversion comes up regularly in several professional contexts:
- API Migration: When updating a legacy SOAP API to REST, you need to convert XML request and response formats to JSON. This tool helps verify the expected output structure before writing code
- Data Import: Many enterprise systems export data as XML files. Converting them to JSON makes the data easier to work with in modern programming languages like Python and JavaScript, where JSON parsing is built in
- Configuration Conversion: Some build tools and frameworks accept both XML and JSON configuration files. Converting between formats lets you pick the one that best fits your workflow
- Testing and Debugging: When an external service returns XML, converting it to JSON makes the structure easier to read and compare against expected values during testing
- Documentation: JSON is more compact and readable in technical documentation. Converting XML examples to JSON helps create cleaner API docs
Understanding the Attribute Prefix Option
XML attributes have no direct equivalent in JSON. When an XML element has attributes, the converter must store them separately from child elements. The attribute prefix option controls how this works:
@attributes (default): Groups all attributes under a key named @attributes. This is the convention used by most XML-to-JSON libraries and is immediately recognizable to developers familiar with tools like xml2js or Jackson.
_attributes: Uses an underscore prefix instead. Some JSON processing pipelines reject keys starting with @ because they conflict with special selectors in query languages like MongoDB or JSONPath. The underscore prefix avoids this issue.
Both options produce valid JSON. Choose @attributes for general use and switch to _attributes if your downstream tools have trouble with the @ symbol.
Handling Arrays and Repeated Elements
One of the trickiest parts of XML-to-JSON conversion is deciding when to use arrays. In XML, repeated sibling elements with the same tag name are common:
<items><item>A</item><item>B</item></items>
This converter automatically detects repeated sibling tags and wraps them in a JSON array:
{"items": {"item": ["A", "B"]}}
When only a single element exists with a given tag name, it remains a plain value rather than a single-element array. This is the standard behavior for most converters, but it means your code should handle both cases when processing the output. If you always need arrays for certain fields, you can post-process the JSON to wrap single values in brackets.
Self-closing tags like <active/> are treated as empty strings in the output.
XML vs JSON Feature Comparison
Understanding the differences between XML and JSON helps you pick the right format for your project:
- Readability: JSON is more compact and easier for humans to scan. XML is more verbose but self-documenting through tag names
- Data Types: JSON supports strings, numbers, booleans, null, objects, and arrays natively. XML treats everything as text unless a schema defines types
- Attributes: XML supports attributes on elements, which have no direct JSON equivalent. This converter maps them to nested objects
- Namespaces: XML supports namespaces for avoiding name conflicts across large systems. JSON has no namespace concept
- Comments: XML allows inline comments. JSON does not support comments, though some parsers accept them as extensions
- Schema Validation: XML has XSD and DTD for strict schema validation. JSON has JSON Schema, which is less established but growing
- File Size: JSON files are typically 30-50% smaller than equivalent XML because they lack closing tags and attribute syntax
Frequently Asked Questions
Does this converter handle XML namespaces?
Yes. The converter preserves namespace prefixes in the JSON output. For example, <soap:Envelope> becomes a key named "soap:Envelope" in the JSON. The namespace URI declared in xmlns attributes is also preserved as an attribute. If you need to strip namespaces, remove the prefix declarations from your XML before converting.
What happens to XML comments during conversion?
XML comments are discarded during conversion. JSON does not support comments, so there is no way to preserve them. If the comments contain important information, copy them into a separate field or document them elsewhere before converting.
Can I convert JSON back to XML with this tool?
This tool handles XML-to-JSON conversion only. The reverse process (JSON to XML) requires additional decisions about element vs attribute mapping, array handling, and root element naming that are not addressed here. For round-trip conversion, use a dedicated library in your programming language such as xml2js for Node or xmltodict for Python.
Why does a single element not become an array?
When only one element of a given tag name exists, the converter outputs it as a plain value instead of a single-element array. This keeps the output clean and avoids unnecessary nesting. However, if your code expects arrays for certain fields, you should add a check that wraps single values in brackets during post-processing. Most XML-to-JSON libraries follow this same convention.
Is there a size limit for the XML input?
There is no hard limit enforced by this tool. The practical limit depends on your device memory and processing power. Documents up to a few thousand elements convert instantly on modern hardware. For very large XML files with tens of thousands of nodes, a command-line tool or streaming parser will perform better because it processes the document incrementally rather than loading it all into memory at once.