# CSV Header Normalizer (snake/camel/Pascal/kebab) (`stellar_ballet_0bu/csv-header-normalizer`) Actor

Rename CSV column headers to snake\_case, camelCase, PascalCase, kebab-case, SCREAMING\_SNAKE, lowercase, Title Case, or preserve. Per-column override map. Pure JS, zero deps, zero anti-bot risk.

- **URL**: https://apify.com/stellar\_ballet\_0bu/csv-header-normalizer.md
- **Developed by:** [Nikita S](https://apify.com/stellar_ballet_0bu) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.00 / 1,000 header normalizeds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.
Actors are written with capital "A".

## 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.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js/docs.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python/docs.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## CSV Header Normalizer

Rename CSV column headers to a chosen case style. Pairs with every CSV Actor in this portfolio.

### What it does

- Reads a CSV from inline text (`csv`) or a public URL (`csvUrl`).
- Renames all headers using one of: `snake_case`, `camelCase`, `PascalCase`, `kebab-case`, `SCREAMING_SNAKE`, `lowercase`, `Title Case`, `preserve`.
- Optional per-column **override map**: a `{"Original Header": "exact new header"}` object whose entries take precedence over the style.
- Preserves column order; preserves row order.
- Detects **collisions** and disambiguates by suffix (`_2`, `_3`, ...). All collisions are recorded in the `SUMMARY.collisions` array.
- Detects **SQL-reserved** generated names (`select`, `from`, `where`, ...) and appends `_col`.
- Names starting with a digit get a leading `_`.
- Emits one `rename` row per header in the dataset (with `original`, `newName`, `source: 'style' | 'override'`, `style`).
- Emits the serialized output CSV in the `OUTPUT` key-value store and a single dataset row containing the full CSV.
- Pure JS, zero deps, no headless browser, no anti-bot risk, no login.

### Allowed case styles

| Style         | Example            |
|---------------|--------------------|
| `snake_case`  | `first_name`       |
| `camelCase`   | `firstName`        |
| `PascalCase`  | `FirstName`        |
| `kebab-case`  | `first-name`       |
| `SCREAMING_SNAKE` | `FIRST_NAME`   |
| `lowercase`   | `firstname`        |
| `Title Case`  | `First Name`       |
| `preserve`    | (no change)        |

### Input

| Field         | Type    | Default | Description |
|---------------|---------|---------|-------------|
| `csv`         | string  | `""`    | Inline CSV body. Leave empty to fetch from `csvUrl`. |
| `csvUrl`      | string  | `""`    | Public URL of a CSV file. Used when `csv` is empty. |
| `delimiter`   | string  | `","`   | Field delimiter. Use `\\t` for TSV. |
| `hasHeader`   | bool    | `true`  | Treat first row as header. Required for normalization. |
| `style`       | string  | `snake_case` | Target case style (see table). |
| `overrideMap` | object  | `{}`    | Per-column rename override. `{"First Name": "firstName"}`. |
| `maxRows`     | int     | `0`     | Cap on rows processed. 0 = no cap. |
| `timeoutSec`  | int     | `30`    | Fetch timeout. |
| `maxBytes`    | int     | `10000000` | Fetch size cap. |
| `eol`         | string  | `lf`    | `lf` or `crlf` for output line endings. |

### Output

- **Dataset rows**:
  - One `rename` row per header: `{ _kind: 'rename', index, original, newName, source, style }`.
  - One `output_csv` row: `{ _kind: 'output_csv', delimiter, eol, headers, rowCount, csv }`.
  - One `error` row on failure.
- **Key-value store**:
  - `OUTPUT` — the serialized output CSV (string).
  - `SUMMARY` — `{ ok, source, style, delimiter, hasHeader, rows, truncated, columns, originalHeaders, newHeaders, renameMap, collisions, overrideCount }`.

### Examples

#### Snake-case from inline

```json
{
  "csv": "First Name,Last Name,E-mail Address\nAda,Lovelace,ada@example.com",
  "style": "snake_case"
}
````

Output headers: `first_name`, `last_name`, `e_mail_address` (note: the dash in `E-mail` splits to `e` + `mail` and joins to `e_mail_address` by default; use `overrideMap` to force `email_address`).

#### With override

```json
{
  "csv": "First Name,LASTNAME,Phone Number",
  "style": "snake_case",
  "overrideMap": {
    "LASTNAME": "last_name",
    "Phone Number": "phoneNumber"
  }
}
```

Output headers: `first_name`, `last_name`, `phoneNumber`.

### What it does not do

- It does **not** modify data rows; only the header row.
- It does **not** validate that the CSV is well-formed beyond basic parsing; pair with `csv-quality-scorecard` for that.
- It does **not** rename based on a schema; pair with `csv-schema-profiler` to inspect the inferred schema first.

### Pairing

- **Before**: `csv-quality-scorecard`, `csv-schema-profiler` (inspect the existing headers + types).
- **After**: any of `csv-dedupe-normalizer`, `csv-join-enricher`, `csv-diff`, `jsonl-to-csv`, `csv-statistical-summary`.
- **In an n8n/Make/Sheets pipeline**: drop a "CSV Header Normalizer" step between the HTTP fetch and the consumer that expects a specific header convention.

### Pricing / cost expectations

Default 256 MB / 512 MB. Streaming CSV parse; per-row cost is sub-millisecond. **Pay-per-event** scheduled to activate after public launch: 1 charge per `header_normalized` event (per column).

### FAQ

**Does it modify data rows?** No — only the header row.

**Does it handle Excel?** Pre-convert to CSV. For programmatic XLSX extraction use [`xlsx-sheet-extractor`](../xlsx-sheet-extractor).

**What if a column normalizes to a duplicate?** It is reported in `collisions[]` in the SUMMARY; the header is still emitted (de-dup is not the job of a normalizer).

**Does it support Excel column names (A, B, C, AA, ...)?** No, this Actor reads the existing header row.

### Related Actors

- [`csv-delimiter-autodetect`](https://apify.com/stellar_ballet_0bu/csv-delimiter-autodetect) — first step if the file is not a clean comma CSV
- [`csv-dedupe-normalizer`](https://apify.com/stellar_ballet_0bu/csv-dedupe-normalizer) — dedupe rows after the header is normalized
- [`csv-quality-scorecard`](https://apify.com/stellar_ballet_0bu/csv-quality-scorecard) — pre-check before normalizing

### Support

Open an issue on the Actor's Store page or contact via the support link in the Store listing.

### License

MIT

# Actor input Schema

## `csv` (type: `string`):

Paste a CSV body. Leave empty to fetch from csvUrl.

## `csvUrl` (type: `string`):

HTTP(S) URL of a CSV file. Used when 'csv' is empty.

## `delimiter` (type: `string`):

Field delimiter. Default ','. For TSV use '\t'.

## `hasHeader` (type: `boolean`):

Treat the first row as a header row.

## `style` (type: `string`):

Case style to apply to all headers. Allowed: snake\_case, camelCase, PascalCase, kebab-case, SCREAMING\_SNAKE, lowercase, Title Case, preserve. OverrideMap entries take precedence over the style.

## `overrideMap` (type: `string`):

Optional JSON object mapping original header -> exact new header. Example: {"First Name": "firstName", "FIRSTNAME": "id"}. Takes precedence over the style.

## `maxRows` (type: `integer`):

Cap on rows processed. 0 = no cap.

## `timeoutSec` (type: `integer`):

Abort the CSV fetch after this many seconds. Ignored when csv is inline.

## `maxBytes` (type: `integer`):

Abort the CSV fetch once this many bytes have been read. Ignored when csv is inline.

## `eol` (type: `string`):

Line ending for the output CSV. Allowed: 'lf' or 'crlf'.

## Actor input object example

```json
{
  "csv": "",
  "csvUrl": "",
  "delimiter": ",",
  "hasHeader": true,
  "style": "snake_case",
  "overrideMap": "",
  "maxRows": 0,
  "timeoutSec": 30,
  "maxBytes": 10000000,
  "eol": "lf"
}
```

# Actor output Schema

## `renameRows` (type: `string`):

Default dataset items: one row per header with \_kind='rename' (or 'output\_csv' / 'error'), originalName, newName, style, renamed boolean.

## `summary` (type: `string`):

Run summary with ok, source, style, delimiter, hasHeader, rows, truncated, columns, originalHeaders, newHeaders, renameMap, collisions, overrideCount.

## `outputCsv` (type: `string`):

Full normalized CSV as text (with the new header row and all input rows).

# 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("stellar_ballet_0bu/csv-header-normalizer").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("stellar_ballet_0bu/csv-header-normalizer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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 stellar_ballet_0bu/csv-header-normalizer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=stellar_ballet_0bu/csv-header-normalizer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "CSV Header Normalizer (snake/camel/Pascal/kebab)",
        "description": "Rename CSV column headers to snake_case, camelCase, PascalCase, kebab-case, SCREAMING_SNAKE, lowercase, Title Case, or preserve. Per-column override map. Pure JS, zero deps, zero anti-bot risk.",
        "version": "0.1",
        "x-build-id": "8BRyY0QvbLwyezTi5"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/stellar_ballet_0bu~csv-header-normalizer/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-stellar_ballet_0bu-csv-header-normalizer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/stellar_ballet_0bu~csv-header-normalizer/runs": {
            "post": {
                "operationId": "runs-sync-stellar_ballet_0bu-csv-header-normalizer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/stellar_ballet_0bu~csv-header-normalizer/run-sync": {
            "post": {
                "operationId": "run-sync-stellar_ballet_0bu-csv-header-normalizer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "csv": {
                        "title": "Inline CSV (string)",
                        "type": "string",
                        "description": "Paste a CSV body. Leave empty to fetch from csvUrl.",
                        "default": ""
                    },
                    "csvUrl": {
                        "title": "CSV URL (public)",
                        "type": "string",
                        "description": "HTTP(S) URL of a CSV file. Used when 'csv' is empty.",
                        "default": ""
                    },
                    "delimiter": {
                        "title": "Field delimiter",
                        "type": "string",
                        "description": "Field delimiter. Default ','. For TSV use '\\t'.",
                        "default": ","
                    },
                    "hasHeader": {
                        "title": "First row is header",
                        "type": "boolean",
                        "description": "Treat the first row as a header row.",
                        "default": true
                    },
                    "style": {
                        "title": "Target case style",
                        "type": "string",
                        "description": "Case style to apply to all headers. Allowed: snake_case, camelCase, PascalCase, kebab-case, SCREAMING_SNAKE, lowercase, Title Case, preserve. OverrideMap entries take precedence over the style.",
                        "default": "snake_case"
                    },
                    "overrideMap": {
                        "title": "Per-column override map (JSON object)",
                        "type": "string",
                        "description": "Optional JSON object mapping original header -> exact new header. Example: {\"First Name\": \"firstName\", \"FIRSTNAME\": \"id\"}. Takes precedence over the style.",
                        "default": ""
                    },
                    "maxRows": {
                        "title": "Max rows",
                        "type": "integer",
                        "description": "Cap on rows processed. 0 = no cap.",
                        "default": 0
                    },
                    "timeoutSec": {
                        "title": "Fetch timeout (seconds)",
                        "type": "integer",
                        "description": "Abort the CSV fetch after this many seconds. Ignored when csv is inline.",
                        "default": 30
                    },
                    "maxBytes": {
                        "title": "Max fetch size (bytes)",
                        "type": "integer",
                        "description": "Abort the CSV fetch once this many bytes have been read. Ignored when csv is inline.",
                        "default": 10000000
                    },
                    "eol": {
                        "title": "Line ending",
                        "type": "string",
                        "description": "Line ending for the output CSV. Allowed: 'lf' or 'crlf'.",
                        "default": "lf"
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
