Convert XML to JSON Instantly (Nested Elements & Attributes)
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.
How to Use XML to JSON Converter
Quick Start Guide
- Paste XML: Copy your XML markup into the input area
- Configure Options: Choose attribute handling and JSON formatting preferences
- Convert: Click "Convert to JSON" to transform your XML
- Copy or Download: Use the output buttons to copy or download the JSON
- 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:
- Validate JSON syntax
- Test with consuming application
- Verify data integrity
- Check array handling
- 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
| XML | JSON |
|---|---|
<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:
- Fetch XML from SOAP endpoint
- Convert to JSON using this tool
- Process JSON in your application
- 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
Most Viewed Tools
TOTP Code Generator
Generate time-based one-time passwords from a TOTP secret key. Enter your base32 secret, choose a period and digit length, and get the current and next codes with a live countdown timer. Useful for testing and debugging 2FA integrations.
Use Tool →JSON to Zod Schema Generator
Generate Zod validation schema code from a JSON sample object. Infers z.string(), z.number(), z.boolean(), z.array(), z.object(), and z.null() types automatically. Handles nested objects, arrays of objects with optional field detection, and outputs copy-ready TypeScript with import and z.infer type alias.
Use Tool →JSONL / NDJSON Formatter
Format, validate, and inspect JSON Lines (JSONL) and NDJSON files. Validates each line individually, reports parse errors by line number, outputs compact JSONL or a pretty-print preview, and lets you download the cleaned file.
Use Tool →Secret and Credential Scanner
Scan pasted text, code, or config files for accidentally exposed API keys, tokens, passwords, and private keys. Detects 50+ secret types across AWS, GitHub, Stripe, OpenAI, and more — all client-side, nothing leaves your browser.
Use Tool →TLS Cipher Suite Checker
Check TLS protocol version compatibility and cipher suite strength ratings against current best practices. Supports IANA and OpenSSL cipher names — rates each suite as Strong, Weak, or Deprecated and explains why.
Use Tool →Password Entropy Calculator
Calculate the information-theoretic bit entropy of any password or API key. Detects character set pools automatically, shows the total number of possible combinations, and estimates crack time across five attack scenarios from rate-limited web logins to GPU cracking clusters.
Use Tool →TOML Config Validator
Validate TOML configuration file syntax and report errors with line numbers. Paste any TOML content — Cargo.toml, pyproject.toml, config.toml — and instantly see a green checkmark with key counts and structure stats, or a precise error message pointing to the exact line. Includes a collapsible JSON structure preview to confirm what was parsed.
Use Tool →Content Security Policy Generator
Build Content Security Policy headers interactively. Toggle directives like script-src, style-src, and img-src, select allowed source tokens, and add custom origins. Instantly outputs your CSP as an HTTP header, meta tag, Nginx directive, or Apache header.
Use Tool →Related Data Engineering & Processing Tools
Dataset Analyzer
FeaturedUpload a CSV, Excel, or JSON file to understand its structure, quality, and patterns. Get column profiles, data quality scores, duplicate detection, outlier analysis, and AI-powered insights — all in your browser.
Use Tool →JSON Formatter & Validator
FeaturedFormat, validate, and pretty-print JSON with our developer-friendly editor.
Use Tool →CSV Deduplicator
Remove duplicate rows from CSV files - Deduplicate CSV data by all columns or specific key columns, keeping first or last occurrence
Use Tool →CSV Data Type Converter
Convert data types in CSV - Transform CSV column values to numbers, booleans, dates with automatic type detection and cleaning
Use Tool →CSV to HTML Table
Convert CSV data to HTML table format with customizable styling. Generate clean, semantic table markup instantly.
Use Tool →CSV Column Renamer
Rename CSV columns - Change CSV column headers and standardize naming conventions with camelCase, snake_case, or Title Case
Use Tool →CSV Format Validator
Validate CSV format - Check CSV files for errors, inconsistent columns, empty values, and formatting issues
Use Tool →XPath Validator
Validate XPath expressions instantly in your browser. Paste an optional XML document to evaluate the expression and see matched nodes. Supports XPath 1.0 with all axes, predicates, and built-in functions.
Use Tool →Share Your Feedback
Help us improve this tool by sharing your experience