# Sitemap to JSON — sitemap.xml to structured URL list (`variable_paddock/sitemap-to-json`) Actor

Parse sitemap.xml and sitemap indexes into structured JSON or CSV: url, lastmod, changefreq, priority. Follows sitemap indexes one level deep, zero parsing dependencies, no API keys. Great for SEO audits, crawl seeding, content inventories and site migrations.

- **URL**: https://apify.com/variable_paddock/sitemap-to-json.md
- **Developed by:** [Tang](https://apify.com/variable_paddock) (community)
- **Categories:** SEO tools, Developer tools
- **Features:** Limited permissions
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

## 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

## Sitemap to JSON / CSV

Parse `sitemap.xml` and **sitemap indexes** into structured data. Zero parsing dependencies: Node `http`/`https` + regex XML parsing (only runtime dependency is the Apify platform SDK).

### Output

#### json mode — one dataset record per URL

```json
{
  "sitemapUrl": "https://example.com/sitemap.xml",
  "url": "https://example.com/page-1",
  "lastmod": "2026-11-01",
  "changefreq": "daily",
  "priority": "0.8"
}
```

#### csv mode — one record per sitemap

```json
{
  "sitemapUrl": "https://example.com/sitemap.xml",
  "urlCount": 123,
  "csv": "url,lastmod,changefreq,priority\r\n\"https://...\",2026-11-01,daily,0.8",
  "fetchedAt": "..."
}
```

CSV follows **RFC4180** (quotes fields containing comma/quote/newline; rows end with `\r\n`).

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `sitemapUrls` | array of strings | — (required) | Sitemap or sitemap-index URLs (local path / `file://` works locally) |
| `maxUrls` | integer | `500` | Total URL entries to output (1–50000) |
| `outputMode` | `json` / `csv` | `json` | Per-URL records or per-sitemap CSV |

### Behavior

- **Sitemap index recursion is one level deep** (index → child sitemaps; child indexes are not followed again).
- Supports **gzip** (Content-Encoding or `.gz` extension) and follows up to 5 HTTP redirects.
- Missing `lastmod` / `changefreq` / `priority` are returned as `null`.
- Per-source failures are logged; other sitemaps continue. In csv mode a failed source returns `{ sitemapUrl, error }`.
- `maxUrls` caps the total emitted across all sitemaps; child sitemaps stop being fetched once the cap is reached.

### Local run

```bash
npm install
mkdir -p storage/key_value_stores/default
echo '{"sitemapUrls":["https://example.com/sitemap.xml"],"maxUrls":50}' > storage/key_value_stores/default/INPUT.json
node src/main.js
## results: storage/datasets/default/*.json
```

Verified locally with a fixture sitemap index (2 child sitemaps, 5 URLs) in both json and csv modes.

### Limitations

- Not a crawler: it only reads sitemaps, it does not fetch the listed pages.
- Text-layer only: no rendering, no JS, no link discovery outside sitemaps.
- Very large sitemaps are capped by `maxUrls` and 50 child sitemaps per index.
- Compressed sitemaps inside a `.tar.gz` bundle are not supported (plain `.xml.gz` is).

### Platform notes

- `.actor/actor.json`: `actorSpecification: 1`, `version: "0.0"`, input/readme copies inside `.actor/`.
- `package.json` `main`/`start` = `src/main.js`; only dependency is `apify`.
- Dockerfile: `node:22-slim` + `npm ci --omit=dev` + `CMD node src/main.js`.
- When creating the Actor, pass **source file contents as plain text**, not base64.

# Actor input Schema

## `sitemapUrls` (type: `array`):

One or more sitemap.xml or sitemap-index URLs (http/https, or local path/file:// for local runs). Sitemap indexes are followed one level deep.

## `maxUrls` (type: `integer`):

Maximum total URL entries to output across all sitemaps (1-50000).

## `outputMode` (type: `string`):

json = one record per URL with sitemapUrl/url/lastmod/changefreq/priority; csv = one record per sitemap with an RFC4180 CSV table.

## Actor input object example

```json
{
  "maxUrls": 500,
  "outputMode": "json"
}
```

# Actor output Schema

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

Each item: sitemapUrl, url, lastmod, changefreq, priority (csv mode adds csv).

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("variable_paddock/sitemap-to-json").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("variable_paddock/sitemap-to-json").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 '{}' |
apify call variable_paddock/sitemap-to-json --silent --output-dataset

```

## MCP server setup

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

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/N9qpfKXLGX93Se5al/builds/GqZgRqw9otfo7gyCD/openapi.json
