# XML to JSON Converter - Feeds, Sitemaps and Exports to JSON (`kotaro-project/xml-to-json-converter`) Actor

Convert XML from up to 20 URLs or pasted text into JSON files with a download link and a preview. Choose how attributes are named, which elements are always arrays, and whether to drop namespaces. XML with a DTD or entities is refused, so XXE is not possible. Pay per file converted.

- **URL**: https://apify.com/kotaro-project/xml-to-json-converter.md
- **Developed by:** [KOTARO project](https://apify.com/kotaro-project) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 file converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## XML to JSON Converter

Turn XML into JSON: RSS and Atom feeds, sitemaps, product exports, SOAP answers, KML and more. Give URLs, paste XML, or both. Each source becomes one JSON file with a download link and a short preview.

### What you get

For every source:

- **downloadUrl**: the link to the JSON file
- **preview**: the first 1,500 characters of the JSON, to check the shape at a glance
- **elements**: how many XML elements were read
- **sizeBytes** of the JSON

### Input

| Field | What it is |
|---|---|
| `xmlUrls` | Public addresses of XML files, up to 20, each up to 50 MB |
| `xmlText` | XML pasted as text |
| `keepAttributes` | Keep attributes such as `id="1"` |
| `attributePrefix` | Put before attribute names, default `@` (so `id` becomes `@id`) |
| `textKey` | Name for the text of an element that also has attributes, default `#text` |
| `alwaysArray` | Element names that always become arrays, such as `item`, so every file has the same shape |
| `stripNamespaces` | Write `dc:title` as `title` |
| `prettyPrint` | Indent the JSON |

The sample input converts IANA's public list of media types and a small pasted catalog, so you can see results in a few seconds.

### Safety

XML with a DTD or entities is **refused**. This blocks external entities (XXE), entity expansion bombs and external DTDs. Only the files you name are downloaded, and internal or private addresses are refused.

### Price

You pay once per file converted (`file-converted`). Sources that cannot be downloaded, are refused or are not valid XML are **not charged**. An empty input ends at once with a free note.

# Actor input Schema

## `xmlUrls` (type: `array`):

Public addresses of XML files (feeds, sitemaps, exports), up to 20, each up to 50 MB. Each one becomes one JSON file. Internal addresses are refused.

## `xmlText` (type: `string`):

XML text to convert, in addition to the URLs. XML with a DTD or entities is refused for safety.

## `keepAttributes` (type: `boolean`):

Keep XML attributes such as id="1" in the JSON.

## `attributePrefix` (type: `string`):

Put this before attribute names so they do not clash with element names. Default @, so id becomes @id. Can be empty.

## `textKey` (type: `string`):

Name used for the text of an element that also has attributes. Default #text.

## `alwaysArray` (type: `array`):

Element names that should always become a JSON array, even when only one is present, such as item or book. This keeps the JSON shape the same for every file.

## `stripNamespaces` (type: `boolean`):

Write dc:title as title. Turn on for feeds and sitemaps if you do not need the namespace prefixes.

## `prettyPrint` (type: `boolean`):

Indent the JSON file so it is easy to read. Turn off for a smaller file.

## Actor input object example

```json
{
  "xmlUrls": [
    "https://www.iana.org/assignments/media-types/media-types.xml"
  ],
  "xmlText": "<catalog><book id=\"1\"><title>Kokoro</title><price currency=\"JPY\">880</price></book><book id=\"2\"><title>Botchan</title><price currency=\"JPY\">495</price></book></catalog>",
  "keepAttributes": true,
  "attributePrefix": "@",
  "textKey": "#text",
  "stripNamespaces": false,
  "prettyPrint": true
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "xmlUrls": [
        "https://www.iana.org/assignments/media-types/media-types.xml"
    ],
    "xmlText": "<catalog><book id=\"1\"><title>Kokoro</title><price currency=\"JPY\">880</price></book><book id=\"2\"><title>Botchan</title><price currency=\"JPY\">495</price></book></catalog>"
};

// Run the Actor and wait for it to finish
const run = await client.actor("kotaro-project/xml-to-json-converter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "xmlUrls": ["https://www.iana.org/assignments/media-types/media-types.xml"],
    "xmlText": "<catalog><book id=\"1\"><title>Kokoro</title><price currency=\"JPY\">880</price></book><book id=\"2\"><title>Botchan</title><price currency=\"JPY\">495</price></book></catalog>",
}

# Run the Actor and wait for it to finish
run = client.actor("kotaro-project/xml-to-json-converter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "xmlUrls": [
    "https://www.iana.org/assignments/media-types/media-types.xml"
  ],
  "xmlText": "<catalog><book id=\\"1\\"><title>Kokoro</title><price currency=\\"JPY\\">880</price></book><book id=\\"2\\"><title>Botchan</title><price currency=\\"JPY\\">495</price></book></catalog>"
}' |
apify call kotaro-project/xml-to-json-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kotaro-project/xml-to-json-converter"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/GhYK4GEYLm2AJYobX/builds/pNBvTD9UOCryibeDM/openapi.json
