XML to JSON · 6 min read
Convert SOAP and REST API XML Responses to JSON
Despite the dominance of JSON APIs, many enterprise systems still communicate in XML. SOAP web services, legacy REST endpoints, and government data feeds all return XML. Converting these responses to JSON is essential for modern data pipelines. This guide covers the XML to JSON Converter with real-world XML patterns.
Why XML API Responses Are Tricky
XML from real APIs has features that simple converters can't handle:
- XML namespaces —
soap:Envelope,ns1:GetUserResponse— prefix clutter that needs stripping. - SOAP envelope structure — an outer envelope, header, and body wrapping the actual payload.
- CDATA sections — embedded content wrapped in
<![CDATA[...]]>that hides HTML, JSON, or XML inside. - Repeating elements — multiple
<item>tags that should become a JSON array, not overwrite each other. - Mixed content — elements with both text and child elements.
The converter handles all these patterns automatically, with zero configuration needed for common use cases.
1. Converting a SOAP Response
SOAP envelopes wrap the actual data inside a Body element. Consider this response:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUserResponse xmlns="http://api.example.com/users">
<User>
<ID>1001</ID>
<Name>Alice Johnson</Name>
<Email>alice@example.com</Email>
<Role>admin</Role>
</User>
</GetUserResponse>
</soap:Body>
</soap:Envelope>
After conversion, the output strips namespaces and unwraps the envelope:
{
"GetUserResponse": {
"User": {
"ID": "1001",
"Name": "Alice Johnson",
"Email": "alice@example.com",
"Role": "admin"
}
}
}
Clean, readable JSON — no SOAP envelope clutter.
2. CDATA and Namespace Handling
Some APIs embed HTML or JSON content inside CDATA sections. The converter extracts the raw text:
<response>
<status>success</status>
<content><![CDATA[{"internal": "json embedded here"}]]></content>
</response>
The content field becomes a plain string containing the embedded JSON. You can then parse it further using the JSON Editor.
XML namespace prefixes are stripped by default. For example, soap:Body becomes Body in the JSON output. If you need to preserve namespace information, configure the attribute prefix setting (default @) to keep namespace declarations as metadata.
3. Automatic Array Detection
When XML has multiple sibling elements with the same tag name, the converter automatically creates a JSON array:
<invoices> <invoice><id>INV-001</id><total>150.00</total></invoice> <invoice><id>INV-002</id><total>275.50</total></invoice> <invoice><id>INV-003</id><total>89.99</total></invoice> </invoices>
Becomes a JSON array of invoice objects, preserving all data without loss.
Try the Free XML to JSON Converter
Convert SOAP envelopes, REST XML, and legacy API responses to clean JSON. No signup, no tracking of your content.
Convert XML to JSON Now →Best Practices for XML API to JSON Conversion
- Verify namespace handling. Check that namespace prefixes are stripped as expected. If a key contains a colon, adjust the attribute prefix setting to strip or preserve it.
- Check CDATA content. CDATA often contains embedded structures. After conversion, inspect the string values that came from CDATA — they may need additional parsing.
- Validate array detection. Ensure single-item elements are treated consistently. The default "Detect Arrays" mode correctly handles both single and repeated elements.
- Use with the JSON Editor. After converting, use the JSON Editor to format and validate the output before using it in your application.
- Compare before and after. Use JSON Diff to compare the converted JSON against expected output to catch any conversion issues.
Frequently Asked Questions
How do I convert a SOAP XML response to JSON?
Paste your SOAP XML (including the Envelope, Header, and Body tags) into the XML to JSON converter. The tool strips the SOAP envelope structure, resolves namespace prefixes, and outputs the clean JSON payload. CDATA sections inside SOAP responses are also handled automatically.
Does the tool handle XML namespaces during conversion?
Yes. XML namespace prefixes like soap:, ns1:, or xsi: are stripped by default, leaving clean key names. You can also choose to keep namespace prefixes as part of the JSON key name by configuring the attribute prefix setting.
How are CDATA sections converted?
CDATA sections are treated as plain text content. The converter extracts the text inside the CDATA wrapper and outputs it as a regular string value in the JSON. This preserves HTML, XML, or JSON content that was embedded inside CDATA.
Can I convert REST API XML responses to JSON?
Yes. REST APIs that return XML payloads (common in legacy systems or enterprise APIs) convert easily. The tool handles nested elements, repeated tags (which become JSON arrays), attributes, and text content without any configuration.
Is my XML API data safe with this converter?
100% safe. All conversion happens in your browser. Your XML data never leaves your computer. No server uploads, no storage, no tracking of your content. The tool works offline once the page is loaded.