XML to JSON
Convert XML to JSON instantly for APIs, integrations, and modern apps. Paste your XML and generate clean JSON output in seconds—ideal for SOAP/legacy feeds, data migration, and debugging. Fast, secure, and free to use with no registration required.
Result
The XML to JSON Converter transforms XML data into JSON format. Paste your XML directly into the input field, load it from a URL, or upload a file — then click Convert to get the JSON output. The result can be copied to clipboard or saved as a text file.
XML and JSON are both structured data formats, but they represent data differently and have different capabilities. XML supports attributes, namespaces, mixed content, and processing instructions — none of which have direct equivalents in JSON. This converter handles the translation, but understanding the mapping rules helps you anticipate the output and plan any post-processing your application may need.
How to use the XML to JSON Converter
Paste your XML into the input field, or click Load from URL to fetch an XML endpoint or feed, or upload an XML file.
Ensure the XML is well-formed before converting: every opening tag must have a matching closing tag, tags must be correctly nested, and attribute values must be quoted.
Click Convert to JSON.
Review the JSON output. Pay particular attention to how repeated elements and attributes have been handled — these are the two most common sources of unexpected output.
Copy the JSON to clipboard, or save it as a text file.
Worked conversion example
The following XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<product id="P001" inStock="true">
<name>Widget Pro</name>
<price>29.99</price>
<tags>
<tag>hardware</tag>
<tag>sale</tag>
</tags>
</product>
</catalog>
Converts to JSON output similar to:
{
"catalog": {
"product": {
"@id": "P001",
"@inStock": "true",
"name": "Widget Pro",
"price": 29.99,
"tags": {
"tag": ["hardware", "sale"]
}
}
}
}
Key observations from this example: (1) The XML declaration is dropped — it has no JSON equivalent. (2) The XML attributes id and inStock are prefixed with @ to distinguish them from element names — a common but not universal convention. (3) The price text '29.99' is coerced to the number 29.99, not kept as a string. (4) The two <tag> repeated sibling elements become a JSON array ["hardware", "sale"]. (5) The XML nesting catalog → product → tags → tag maps directly to JSON nesting. If there were only one <tag> element, it would likely become a string rather than a one-element array — a common inconsistency to handle in post-processing.
XML-to-JSON mapping rules
Understanding how each XML construct maps to JSON helps you anticipate and verify the output:
| XML construct | JSON equivalent | Notes and caveats |
| Element with text content | String or typed value | An element containing only text becomes a JSON key with its text as the value: <name>Alice</name> → "name": "Alice". The converter may attempt to coerce numeric text to a number and "true"/"false" text to a boolean. |
| Nested element | Nested JSON object | A parent element containing child elements becomes a JSON object: <user><id>1</id><name>Alice</name></user> → "user": {"id": 1, "name": "Alice"}. |
| Repeated sibling elements | JSON array | Multiple elements with the same tag name become a JSON array: three <item> elements → "item": ["a","b","c"]. Important: a single <item> element typically becomes a string, not a one-element array. This inconsistency requires post-processing if consistent array output is needed. |
| XML attribute | @attr key or merged value | XML attributes have no direct JSON equivalent. Common conventions: prefix attribute keys with @ (e.g. id="1" → "@id": "1"), merge with the element's text using a special "#text" key, or drop attributes entirely. The exact behaviour depends on the converter — always verify output when attributes are present. |
| Empty element | null or empty string or {} | An empty self-closing element like <field/> or an element with no content may become null, an empty string "", or an empty object {} depending on the converter. Verify the output matches what your target system expects. |
| Mixed content | Lossy or complex | XML allows mixed content — an element containing both text and child elements (e.g. <p>Hello <b>World</b></p>). JSON has no equivalent structure. Converters handle this inconsistently and the result is often lossy. Mixed content XML is the hardest case to convert cleanly. |
| XML declaration | Dropped | The XML declaration <?xml version="1.0" encoding="UTF-8"?> is processing metadata with no content equivalent. It is always dropped during conversion — it has no place in JSON. |
| XML namespace | Prefix in key or dropped | XML namespaces (xmlns:ns='...') allow elements from different schemas to coexist without name conflicts. JSON has no namespace concept. The namespace prefix may be retained in the key name (ns:element → "ns:element"), stripped, or handled via a special key. SOAP envelopes use namespaces extensively — verify output carefully when converting SOAP XML. |
The single-element array problem: when a parent element has multiple repeated child elements, the converter creates a JSON array. But when only one child element is present, most converters produce a single value rather than a one-element array. This means { "item": "value" } and { "item": ["value"] } are both possible outputs for the same logical list, depending on the data. If your application code relies on the output being an array, it must handle this inconsistency — either by normalising single-child elements to arrays in post-processing, or by ensuring the converter always wraps child elements in an array.
What is well-formed XML?
XML validity has two levels — well-formed and valid. Conversion requires the XML to be at least well-formed:
Well-formed XML (required for conversion)
Every opening tag has a matching closing tag: <name>Alice</name> or self-closing <name/>.
Tags are correctly nested — no overlapping tags: <a><b></b></a> is correct; <a><b></a></b> is not.
Attribute values are always quoted (double or single quotes are both valid in XML).
There is exactly one root element — XML documents cannot have multiple top-level elements.
The document uses correct XML character escaping for special characters: & must be &, < must be <, > must be >, " must be " in attribute values.
Valid XML (optional — requires a DTD or XSD schema)
Valid XML additionally conforms to a specific schema (DTD or XSD) that defines which elements and attributes are allowed and their data types. Validity is not required for conversion — well-formed XML is sufficient. However, if you are converting SOAP responses or other schema-defined XML, understanding the schema helps you predict how elements and types will map to JSON.
Converting SOAP XML responses
SOAP (Simple Object Access Protocol) web services return XML envelopes with a specific structure. Converting SOAP responses to JSON is a common use case when integrating a SOAP service with a modern JSON-based application. Key considerations for SOAP XML:
SOAP responses are wrapped in a <soap:Envelope> element containing a <soap:Body>. The actual payload is nested inside the Body. The JSON output will include these wrapper elements — your application needs to navigate to the payload within the converted structure.
SOAP namespaces (xmlns:soap, xmlns:ns, etc.) are used extensively. The converter may retain namespace prefixes in key names (soap:Envelope, ns:Response) or handle them via special keys. Review the output structure carefully before integrating.
SOAP faults (error responses) use a specific structure: <soap:Fault> containing <faultcode>, <faultstring>, and optionally <detail>. Ensure your error handling code navigates to the correct path in the converted JSON.
When to use XML to JSON vs JSON to XML
Use XML to JSON when: you receive XML from a legacy system, SOAP service, or XML feed and your application works with JSON; you are migrating data from an XML-based system to a JSON-based database or API; or you want to inspect or debug an XML response in a format that is easier to read.
Use JSON to XML when: you have JSON data that needs to be sent to a SOAP service or legacy system that requires XML; you are generating XML feeds or configuration files from JSON data; or a target system accepts only XML input.
Usage limits
| Guest (no account) | Registered (free) | |
| Daily conversions | 25 per day | 100 per day |
Related tools
JSON to XML — the reverse conversion. Convert JSON to XML for SOAP services, legacy integrations, and XML-based workflows.
JSON Validator — validate the JSON output after conversion to confirm it is syntactically correct.
JSON Formatter — format and pretty-print the converted JSON for readability.
Frequently asked questions
How does XML to JSON conversion work?
The converter parses the XML document into its element tree (a hierarchical structure of elements, attributes, text nodes, and comments). It then traverses this tree and serialises each node as JSON. XML elements become JSON keys. Text content becomes string values (with optional type coercion for numbers and booleans). Repeated sibling elements with the same tag name become JSON arrays. XML attributes are typically converted using a prefix convention (commonly @) to distinguish them from element names. The XML declaration and comments are dropped.
What is well-formed XML and why does it matter for conversion?
Well-formed XML means every opening tag has a matching closing tag, tags are correctly nested, attribute values are quoted, there is one root element, and special characters are correctly escaped. XML must be well-formed to be parsed — if any of these rules are violated, the XML parser cannot build the element tree, and conversion fails. Common sources of malformed XML: missing closing tags (especially </br> vs <br/> confusion from HTML), unescaped & characters (use &), and content outside the root element.
How are XML attributes handled in the JSON output?
XML attributes have no direct JSON equivalent. The most common convention is to prefix attribute keys with @ — an element <product id='P001'> produces "@id": "P001" in the JSON. Some converters merge attributes with the element's text content using a special #text key: <tag attr='val'>text</tag> might produce { "@attr": "val", "#text": "text" }. Other converters simply drop attributes. The behaviour depends on the converter — always verify how attributes are handled when the XML you are converting uses them for meaningful data.
Why does a single XML element produce a string but multiple produce an array?
Most converters create a JSON array only when they encounter multiple sibling elements with the same tag name. If only one element is present, they produce a single value. This means the same data structure can produce different JSON output depending on how many items are in a list — one item gives a string, two or more give an array. This is a well-known inconsistency in XML-to-JSON conversion. If your application code always expects an array, add a post-processing step that normalises single values to one-element arrays for any field that logically represents a list.
Can I convert a SOAP response to JSON?
Yes. Paste the full SOAP XML response (including the soap:Envelope wrapper) and the converter will produce JSON. The output will include the SOAP envelope structure as nested JSON keys. Navigate to the payload inside soap:Body in the converted JSON to reach the actual response data. SOAP namespaces (xmlns:soap, xmlns:ns, etc.) may appear as @ keys or be stripped depending on the converter. For regular SOAP integration, a server-side XML parser that navigates the SOAP structure before converting to JSON is more reliable than converting the full envelope.
What XML features cannot be cleanly converted to JSON?
Several XML features have no clean JSON equivalent: XML namespaces (JSON has no namespace concept), mixed content (elements containing both text and child elements), XML comments (JSON has no comment syntax), processing instructions (<?xml-stylesheet ...?>), CDATA sections, and XML entity declarations. These are either dropped, mangled, or converted in non-standard ways that vary between converters. If your XML uses any of these features for meaningful data, plan for post-processing or restructuring the XML before conversion.
Can I load XML from a URL for conversion?
Yes. The Load from URL feature fetches XML from an endpoint — an RSS feed, a SOAP service endpoint, or any publicly accessible XML file. Enter the full URL including the https:// protocol. Note that browser-side CORS restrictions apply: if the endpoint does not include Access-Control-Allow-Origin headers, the browser will block the fetch. Most SOAP services and many RSS feeds do not include CORS headers. For those, copy the XML from your HTTP client (curl, Postman, browser Network tab) and paste it manually.
Is the XML to JSON Converter free?
Yes. The converter is free within the daily usage limits. Guest users can run 25 conversions per day. Registering a free ToolsPiNG account increases the daily limit to 100 conversions per day.