XML to JSON Converter
Convert XML to JSON — CDATA, attributes, namespaces, and pretty-print, all in your browser
Options
Indent
Attributes
Your integration partner sends data as XML but your JavaScript app works with JSON. The conversion isn’t a simple string transformation — XML attributes need a convention (@attr or _attr), CDATA sections need unwrapping, namespaces need handling, and repeated child elements need to become arrays. Getting any of these wrong produces invalid data structures.
Why This Converter (Not the JSON to XML Converter)
PureDevTools has a JSON to XML Converter for the reverse direction. This tool converts XML to JSON — with proper handling of attributes, CDATA, namespaces, type coercion (strings to numbers/booleans), and pretty-print formatting. Everything runs in your browser; no data is sent anywhere.
What Is XML to JSON Conversion?
XML (Extensible Markup Language) and JSON (JavaScript Object Notation) are the two most widely used data interchange formats. XML has been the backbone of enterprise APIs, RSS feeds, SOAP web services, SVG graphics, and configuration files for over two decades. JSON emerged as the dominant format for REST APIs, browser storage, and modern application config because of its compact syntax and native JavaScript support.
Converting XML to JSON is a common task when:
- Migrating from SOAP to REST APIs — SOAP envelopes use XML; most modern REST clients expect JSON
- Consuming RSS or Atom feeds — feed data is XML; your app stores and displays JSON
- Processing configuration files — Maven’s
pom.xml, Ant’sbuild.xml, Spring’sapplicationContext.xml - Integrating third-party data — governments, healthcare (HL7, FHIR), financial, and GIS systems often export XML
- Inspecting XML payloads — JSON is much more readable in a browser devtools console
How This Converter Works
This tool parses your XML entirely in the browser using a custom recursive descent parser and converts it to a clean JSON structure. No data is ever sent to a server. The parser handles the full range of XML constructs:
Elements and Text Content
Each XML element becomes a JSON key. Text-only elements collapse to their string value:
<name>Alice</name>
"Alice"
Elements with only child elements become JSON objects:
<person>
<name>Alice</name>
<age>30</age>
</person>
{
"name": "Alice",
"age": 30
}
Attributes
With the @ Prefix mode, XML attributes are included in the JSON output with a @ prefix on their key names — a widely adopted convention used by tools like Badgerfish and other XML-to-JSON standards:
<user id="42" role="admin">Alice</user>
{
"@id": 42,
"@role": "admin",
"#text": "Alice"
}
With Ignore mode, attributes are omitted entirely, and only element content is kept.
CDATA Sections
CDATA sections (<![CDATA[...]]>) allow raw text to appear inside an element without escaping. Their content is extracted and treated as regular text:
<script><![CDATA[if (x < 10 && y > 0) alert("ok");]]></script>
"if (x < 10 && y > 0) alert(\"ok\");"
Repeated Sibling Elements (Arrays)
When multiple elements share the same tag at the same nesting level, they are automatically grouped into a JSON array:
<items>
<item>Apple</item>
<item>Banana</item>
<item>Cherry</item>
</items>
{
"item": ["Apple", "Banana", "Cherry"]
}
Namespaces
XML namespaces associate element and attribute names with a URI to avoid name conflicts. By default, namespace prefixes are preserved in the JSON output:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>...</soap:Body>
</soap:Envelope>
Enable the Strip Namespaces option to remove all namespace prefixes from element and attribute names, producing cleaner JSON at the cost of namespace distinction.
Type Coercion
With Coerce Types enabled, string values that represent JSON primitives are converted to their native types:
| XML text | JSON value |
|---|---|
"42" | 42 (number) |
"3.14" | 3.14 (number) |
"true" | true (boolean) |
"false" | false (boolean) |
"null" | null |
"" | "" (empty string stays) |
Disable type coercion to keep all values as strings — useful when your downstream system expects strict string types.
xsi:nil Support
Elements with xsi:nil="true" are converted to JSON null, following the XML Schema Instance convention for nullable values.
Comments and Processing Instructions
XML comments (<!-- ... -->) and processing instructions (<? ... ?>) such as the standard XML declaration <?xml version="1.0"?> are silently ignored and not included in the JSON output.
Output Options
Indent Size
Choose 2 spaces (default) or 4 spaces for the JSON indentation. Two spaces is the common convention for configuration files and APIs; four spaces is preferred in some codebases and editors.
Pretty Print
The output is always pretty-printed (human-readable) with line breaks and indentation. Copy the result with the Copy JSON button.
Common XML Sources
SOAP Web Services: SOAP uses an XML envelope with optional headers and a body. Convert the inner body payload to JSON when building REST wrappers or test fixtures.
RSS and Atom Feeds: RSS 2.0 and Atom 1.0 feeds are XML. Convert them to JSON to use feed data in a JavaScript frontend or store in a NoSQL database.
Maven POM files: Maven’s pom.xml stores project metadata, dependencies, and plugin configuration. Converting to JSON makes it easier to script with jq or Node.js.
SVG files: SVG images are XML. While SVG is not directly converted to JSON for rendering, inspecting SVG structure as JSON can help debugging path data and attribute values.
HL7 and FHIR: Healthcare data standards use XML for messaging. FHIR R4 supports both XML and JSON representations; this tool helps convert XML payloads for inspection.
OpenAPI / WSDL: WSDL (Web Services Description Language) is XML. Converting WSDL to JSON can help feed it into documentation generators or code-generation tools.
Frequently Asked Questions
Why is my array showing as an object instead of an array? XML has no native array syntax — arrays are inferred from repeated sibling elements with the same tag name. If only one element with a given tag exists, it becomes a single value rather than a one-element array. To force arrays, you need to preprocess the XML or post-process the JSON output.
What happens to XML comments? Comments are stripped and not included in the JSON output. If you need to preserve comment content, you would need to pre-extract them before conversion.
What is mixed content?
Mixed content occurs when an XML element contains both child elements and text. This tool handles it by storing the text portion under the special "#text" key alongside the child element keys.
Why does my namespace-prefixed XML produce odd-looking keys?
If your XML uses namespace prefixes like soap:Envelope, those prefixes appear in the JSON keys by default (e.g., "soap:Body"). Enable Strip Namespaces to remove the prefix and colon, keeping only the local name.
Is my data sent to a server? No. All parsing and conversion runs entirely in your browser using a custom JavaScript XML parser. Your XML is never transmitted over the network. This tool works offline once the page is loaded.
What is the difference between this tool and the JSON to XML Converter? This tool converts in one direction only: XML input → JSON output, with enhanced support for CDATA, namespaces, and type coercion. The JSON to XML Converter performs the reverse transformation.