πŸ”„

XML to JSON Converter

Convert XML markup to JSON format. Perfect for API modernization, data extraction, integrating legacy XML systems with modern JSON APIs, and SOAP to REST migration.

Developer Tools
Loading tool...

How to Use XML to JSON Converter

Quick Start Guide

  1. Paste XML: Copy your XML markup into the input area
  2. Configure Options: Choose attribute handling and JSON formatting preferences
  3. Convert: Click "Convert to JSON" to transform your XML
  4. Copy or Download: Use the output buttons to copy or download the JSON
  5. Try Examples: Click example buttons to see different conversion scenarios

What is XML to JSON Conversion?

XML to JSON conversion transforms XML (eXtensible Markup Language) into JSON (JavaScript Object Notation) format, enabling modern web applications and APIs to consume legacy XML data.

Purpose: API modernization, SOAP to REST migration, data extraction Input: XML markup with elements and attributes Output: JSON objects and arrays Usage: Legacy system integration, API transformation, data migration

Why Convert XML to JSON?

Modernization Benefits:

  • Integrate legacy XML systems with modern JSON APIs
  • Migrate SOAP web services to REST
  • Reduce data size and improve performance
  • Simplify data consumption in JavaScript applications
  • Enable easier data manipulation in web apps
  • Improve API response times

Common Scenarios:

  • SOAP to REST API migration
  • Legacy system modernization
  • Extracting data from XML configuration files
  • Converting XML feeds to JSON
  • Processing XML API responses in web apps
  • Data warehouse ETL processes

XML vs JSON

XML (eXtensible Markup Language):

  • More verbose with opening/closing tags
  • Supports attributes and namespaces
  • Schema validation (XSD)
  • Better for document markup
  • Industry standard for enterprise systems
  • SOAP web services requirement

JSON (JavaScript Object Notation):

  • Lightweight and compact (30-50% smaller)
  • Native to JavaScript
  • Easy to parse and generate
  • Better for web APIs
  • Faster parsing in browsers
  • Modern API standard

When to convert to JSON:

  • Building modern REST APIs
  • Web application consumption
  • Mobile app data feeds
  • Reducing bandwidth usage
  • Simplifying data processing
  • Improving performance

Conversion Options Explained

Include Attributes

Enabled (recommended): Attributes are prefixed with @ in JSON:

{
  "@id": "123",
  "@type": "user",
  "name": "John"
}

Disabled: Attributes are omitted from output:

{
  "name": "John"
}

When to include:

  • Need complete data preservation
  • Attributes contain important data
  • Round-trip conversion required
  • Metadata is essential

When to exclude:

  • Attributes are not needed
  • Simpler JSON structure desired
  • Only element values matter

Pretty Print JSON

Enabled (recommended):

{
  "user": {
    "id": 1,
    "name": "John"
  }
}

Disabled (compact):

{"user":{"id":1,"name":"John"}}

Use pretty print for:

  • Human readability
  • Development and debugging
  • Documentation
  • Code review

Use compact for:

  • Minimal file size
  • Network transmission
  • Production APIs
  • Storage optimization

Common Use Cases

1. Simple Elements to JSON

Purpose: Convert basic XML elements to JSON object

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <id>1</id>
  <name>John Doe</name>
  <email>john@example.com</email>
</user>

After (JSON):

{
  "user": {
    "id": "1",
    "name": "John Doe",
    "email": "john@example.com"
  }
}

2. Repeated Elements to Arrays

Purpose: Convert repeated XML elements to JSON array

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<users>
  <user>
    <id>1</id>
    <name>Alice</name>
  </user>
  <user>
    <id>2</id>
    <name>Bob</name>
  </user>
</users>

After (JSON):

{
  "users": {
    "user": [
      {
        "id": "1",
        "name": "Alice"
      },
      {
        "id": "2",
        "name": "Bob"
      }
    ]
  }
}

Note: Repeated elements automatically become arrays.

3. Attributes Conversion

Purpose: Handle XML attributes in JSON

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<product id="P001" category="electronics">
  <name>Laptop</name>
  <price currency="USD">999.99</price>
</product>

After (JSON with attributes):

{
  "product": {
    "@id": "P001",
    "@category": "electronics",
    "name": "Laptop",
    "price": {
      "@currency": "USD",
      "#text": "999.99"
    }
  }
}

Note: Attributes use @ prefix, text content uses #text when mixed with attributes.

4. Nested Structure

Purpose: Convert hierarchical XML to nested JSON

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<company>
  <name>Tech Corp</name>
  <address>
    <street>123 Main St</street>
    <city>San Francisco</city>
    <state>CA</state>
  </address>
</company>

After (JSON):

{
  "company": {
    "name": "Tech Corp",
    "address": {
      "street": "123 Main St",
      "city": "San Francisco",
      "state": "CA"
    }
  }
}

5. SOAP Response to JSON

Purpose: Transform SOAP/XML API response to JSON

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<response>
  <status>success</status>
  <code>200</code>
  <data>
    <userId>12345</userId>
    <message>User created</message>
  </data>
</response>

After (JSON):

{
  "response": {
    "status": "success",
    "code": "200",
    "data": {
      "userId": "12345",
      "message": "User created"
    }
  }
}

6. Configuration Files

Purpose: Convert XML config to JSON

Before (XML):

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <database>
    <host>localhost</host>
    <port>5432</port>
  </database>
  <cache enabled="true">
    <ttl>3600</ttl>
  </cache>
</config>

After (JSON):

{
  "config": {
    "database": {
      "host": "localhost",
      "port": "5432"
    },
    "cache": {
      "@enabled": "true",
      "ttl": "3600"
    }
  }
}

Features

Core Functionality

  • Complete XML Parsing: Handles complex XML structures
  • Attribute Support: Optional @ prefix for attributes
  • Array Detection: Automatic array creation for repeated elements
  • Nested Elements: Unlimited nesting depth
  • Entity Decoding: Converts XML entities to characters
  • Pretty Printing: Formatted or compact JSON output

Supported XML Features

Elements:

  • Simple text elements
  • Nested elements
  • Repeated elements (arrays)
  • Empty elements (null values)
  • Mixed content (text + attributes)

Attributes:

  • Element attributes β†’ @attribute
  • Multiple attributes per element
  • Attribute + text content β†’ #text

Other:

  • XML declaration (removed)
  • Comments (removed)
  • Entity references decoded
  • CDATA sections (treated as text)

Conversion Rules

XML β†’ JSON Mapping:

  • Element β†’ Object property
  • Text content β†’ String value
  • Repeated elements β†’ Array
  • Attributes β†’ @attribute properties
  • Mixed content β†’ #text property
  • Empty element β†’ null or empty object

Best Practices

1. Validate XML First

Before conversion:

  • Ensure XML is well-formed
  • Check for unclosed tags
  • Verify proper nesting
  • Test with small sample

Validation tools:

  • Browser XML parser
  • Online XML validators
  • IDE XML linting
  • This tool shows errors

2. Understand Attribute Handling

With attributes enabled:

{
  "@id": "123",
  "name": "John"
}

Without attributes:

{
  "name": "John"
}

Choose based on:

  • Data importance
  • Application requirements
  • JSON structure preferences

3. Handle Arrays Properly

Repeated elements become arrays:

<items>
  <item>A</item>
  <item>B</item>
</items>

Becomes:

{
  "items": {
    "item": ["A", "B"]
  }
}

Note: Single element stays as object, not array.

4. Plan for Data Type Conversion

XML has only strings:

  • All values are strings in JSON
  • Numbers: "123" (not 123)
  • Booleans: "true" (not true)

Post-process if needed:

const data = JSON.parse(jsonOutput);
data.user.id = parseInt(data.user.id);
data.user.active = data.user.active === 'true';

5. Test with Target System

After conversion:

  1. Validate JSON syntax
  2. Test with consuming application
  3. Verify data integrity
  4. Check array handling
  5. Confirm attribute mapping

Technical Details

How XML to JSON Conversion Works

1. Parse XML string
2. Remove XML declaration and comments
3. Identify root element
4. Recursively parse child elements
5. Detect repeated elements (arrays)
6. Extract attributes with @ prefix
7. Handle mixed content with #text
8. Decode XML entities
9. Build JSON object structure
10. Format output (pretty or compact)

Conversion Mapping

XMLJSON
<name>John</name>{"name": "John"}
<item>A</item><item>B</item>{"item": ["A", "B"]}
<user id="1">{"user": {"@id": "1"}}
<count>5</count>{"count": "5"} (string)
<empty />{"empty": null}
<tag attr="x">text</tag>{"tag": {"@attr": "x", "#text": "text"}}

Repeated Element Detection

Automatic array creation:

  • Same tag name appears multiple times
  • Creates array at first repetition
  • Maintains element order

Example:

<root>
  <item>A</item>
  <item>B</item>
</root>

Results in:

{
  "root": {
    "item": ["A", "B"]
  }
}

Limitations

This is a basic converter:

  • No namespace handling (xmlns removed)
  • No CDATA preservation (treated as text)
  • All values become strings (no type inference)
  • Mixed content uses #text convention
  • No schema validation

For advanced conversion:

  • fast-xml-parser: Full-featured with options
  • xml2js: Popular Node.js library
  • xmldom: DOM-based parsing

This tool is best for:

  • Simple XML to JSON conversion
  • Quick one-off transformations
  • SOAP response parsing
  • Learning format differences
  • Privacy-focused use (100% local)

Browser Compatibility

Supported browsers:

  • βœ… Chrome 90+
  • βœ… Firefox 88+
  • βœ… Safari 14+
  • βœ… Edge 90+
  • βœ… Opera 76+

Works on:

  • Desktop: Windows, macOS, Linux
  • Mobile: iOS Safari, Chrome Android
  • Tablets: iPad, Android tablets

Privacy & Security

Client-Side Processing

  • 100% Local: All conversion in your browser
  • No Uploads: XML never sent to server
  • No Storage: Nothing saved or cached
  • No Tracking: No analytics on your data
  • No Accounts: No login required

Safe for Sensitive Data

  • βœ… SOAP API responses
  • βœ… Configuration files
  • βœ… Customer data in XML
  • βœ… Enterprise system data
  • βœ… Personal information

Note: Remove sensitive data before sharing JSON output.

Comparison with Other Tools

XML to JSON Converter vs fast-xml-parser

This Tool:

  • βœ… Browser-based, instant
  • βœ… No installation needed
  • βœ… Privacy-focused (100% local)
  • βœ… Simple interface
  • ❌ Basic parsing only
  • ❌ No type inference

fast-xml-parser / xml2js:

  • βœ… Advanced parsing options
  • βœ… Type inference
  • βœ… Namespace handling
  • βœ… Highly customizable
  • ❌ Requires Node.js
  • ❌ Setup needed

When to use this tool: Quick conversions, simple XML, privacy

When to use libraries: Production apps, complex XML, automation

Integration Tips

Using Converted JSON

1. Copy to Application:

  • Convert your XML
  • Click "Copy JSON"
  • Parse in your JavaScript app
  • Use the data

2. Download File:

  • Convert your XML
  • Click "Download .json"
  • Import into application
  • Process as needed

3. API Integration:

// Convert SOAP XML to JSON
const xmlResponse = await fetchSoapApi();
// Use this tool to convert
const jsonData = JSON.parse(convertedJson);
// Use in your app

Post-Processing Data Types

Convert strings to proper types:

function parseTypes(obj) {
  for (let key in obj) {
    if (typeof obj[key] === 'string') {
      // Try parsing as number
      if (!isNaN(obj[key]) && obj[key] !== '') {
        obj[key] = Number(obj[key]);
      }
      // Parse booleans
      if (obj[key] === 'true') obj[key] = true;
      if (obj[key] === 'false') obj[key] = false;
    } else if (typeof obj[key] === 'object') {
      parseTypes(obj[key]); // Recursive
    }
  }
}

SOAP to REST Migration

Converting SOAP responses:

  1. Fetch XML from SOAP endpoint
  2. Convert to JSON using this tool
  3. Process JSON in your application
  4. Gradually migrate to REST APIs

Note: For production use with namespaces, complex schemas, or type inference requirements, consider using dedicated libraries like fast-xml-parser (JavaScript) or xmltodict (Python). This tool is perfect for simple conversions, quick transformations, and privacy-focused use cases.

Frequently Asked Questions

Related Utility Tools

Share Your Feedback

Help us improve this tool by sharing your experience

We will only use this to follow up on your feedback