XML to JSON Converter

Convert XML documents to JSON format instantly. Modernize legacy data and integrate with REST APIs.

1
Paste your XML here to convert to JSON...
OutputEMPTY
1
 
Formatted output will appear here...

How to Convert XML to JSON

1

Paste Your XML

Copy your XML document and paste it into the input editor.

2

Click Convert → JSON

Use the Convert dropdown and select "to JSON" to transform your data.

3

Copy JSON Output

Copy the JSON result or download it as a .json file.

XML to JSON Conversion Example

XML Input
<user id="1">
  <name>John Doe</name>
  <email>[email protected]</email>
  <active>true</active>
</user>
JSON Output
{
  "user": {
    "@id": "1",
    "name": "John Doe",
    "email": "[email protected]",
    "active": "true"
  }
}

XML to JSON Conversion Rules

XML FeatureJSON Representation
ElementObject with element name as key
AttributeProperty with @ prefix (e.g., @id)
Text content#text property or direct string value
Repeated elementsArray of objects
CDATAString value (markup removed)

Why Convert XML to JSON?

Modernize Legacy Systems

Many enterprise systems still use XML (SOAP services, older databases). Converting to JSON makes data compatible with modern REST APIs, JavaScript frameworks, and NoSQL databases without rewriting entire systems.

Easier JavaScript Processing

While JavaScript can parse XML (DOMParser), working with JSON is much simpler. JSON parses directly to native JavaScript objects with JSON.parse(), allowing immediate property access without DOM traversal.

Smaller Payload Size

JSON is typically 30-50% smaller than equivalent XML due to the absence of closing tags and verbose markup. This means faster network transfer, reduced bandwidth costs, and improved application performance.

API Integration

Most modern APIs (REST, GraphQL) use JSON. Converting XML responses from legacy services to JSON simplifies integration with current technology stacks and third-party services.

Frequently Asked Questions

How are XML attributes handled?
XML attributes are converted to JSON properties with an @ prefix. For example, <user id="1"> becomes {"user": {"@id": "1"}}. This convention distinguishes attributes from child elements.
What about repeated XML elements?
When an XML element appears multiple times, it's converted to a JSON array. For example, multiple <item> elements become "item": [{...}, {...}]. This preserves the list semantics of the original XML.
Is the conversion lossless?
The data content is preserved, but some XML-specific features may be simplified: comments are removed, processing instructions are omitted, and namespace prefixes are handled based on context. The core data structure and values are fully preserved.
Can I convert JSON back to XML?
While we don't currently offer JSON to XML conversion, the @ prefixed properties can help distinguish what should become attributes vs. elements if you need to reconstruct XML later.

Related Conversion Tools