# 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 web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
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.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — 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

Download the OpenAPI definition: https://api.apify.com/v2/actors/ZSxeVay998QK4zAN6/builds/8BRyY0QvbLwyezTi5/openapi.json
