🧩

JSON to XML

Convert JSON data into XML.

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

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

Description

Convert JSON data into XML.

How to Use

1

1. POST a JSON body with `data` (any JSON value).

2

2. Optionally set `root_element` and `pretty`.

3

3. Read the `xml` string from the response.

About This Tool

Converts a JSON value into XML. Object keys become element names; arrays produce repeated elements. The top-level wrapper element is controlled by `root_element` (default: `root`).

Pretty-printing is available via the `pretty` flag; primitives are rendered as element text.

Why Use This Tool

Frequently Asked Questions

How are array items named?
Each array element is wrapped in a singular-named element when possible, or in `<item>` otherwise.
Are attributes produced?
No — keys always become child elements. To control attribute serialization, post-process the XML.
What about special characters?
Text content is XML-escaped automatically (`<`, `>`, `&`, `"`, `'`).

Start using JSON to XML now

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