🧩

XML to JSON

Convert XML into JSON.

POST 1 credit /v1/convert/xml-to-json
curl -X POST "https://convert.toolkitapi.io/v1/convert/xml-to-json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"xml": "<person><name>Alice</name><age>30</age></person>"}'
import httpx

resp = httpx.post(
    "https://convert.toolkitapi.io/v1/convert/xml-to-json",
    json={"xml": "<person><name>Alice</name><age>30</age></person>"},
)
print(resp.json())
const resp = await fetch("https://convert.toolkitapi.io/v1/convert/xml-to-json", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"xml": "<person><name>Alice</name><age>30</age></person>"}),
});
const data = await resp.json();
console.log(data);
# See curl example
Response 200 OK
{
  "json": {"person": {"name": "Alice", "age": "30"}},
  "elements_count": 3
}

Description

Convert XML into JSON.

How to Use

1

1. POST a JSON body with `xml` (or `url`).

2

2. Optionally set `strip_namespaces` and `force_list`.

3

3. Read the structured `json` from the response.

About This Tool

Parses an XML document and returns it as JSON. Elements become object keys, element text becomes string values, and repeated sibling elements become arrays.

Options let you strip namespaces and force certain elements to always be arrays (useful when an element appears once but your consumer expects a list).

Why Use This Tool

Frequently Asked Questions

Are attributes included?
Yes — attributes appear as keys prefixed with `@`.
How are repeated elements handled?
Multiple siblings with the same name become an array. To guarantee arrays for singletons, use `force_list`.
What about CDATA?
CDATA text is returned as the element's string value, like any other text.

Start using XML to JSON now

Get your free API key and make your first request in under a minute.