# CSV transpose

`csv-transpose` · version 1.0.0 · CSV & tables · free, no key needed

Transpose a CSV matrix including the header row, then re-validate headers.

**Use when you need to: csv transpose · transpose csv · csv rotate columns to rows.**

## Supported

- csv transpose
- transpose csv
- csv rotate columns to rows

## Not supported

- jagged fill
- multi-header
- read files

## Behavior

- Reuse baseline parser: the document is a rectangular matrix of header plus data rows.
- Transpose that full matrix (header row is row 0).
- The first row of the transposed matrix becomes the new header and must pass unique/non-empty/byte/column limits.
- Empty document -> csv "".
- Header-only (one row, N columns) becomes N rows and 1 column whose header is the original first header name, data the remaining original headers.
- Reject if transpose would exceed max_columns or max_data_rows.

## Input

- `csv` (string, required): max length 256000

## Output

- `csv` (string, required)
- `rows_in` (integer, required)
- `cols_in` (integer, required)
- `rows_out` (integer, required)
- `cols_out` (integer, required)

## Limits

- max input bytes: 256000
- max data rows: 5000
- max columns: 256
- max header name bytes: 256

## Example

Request input:

```json
{
  "csv": "h1,h2\na,b\nc,d\n"
}
```

Response:

```json
{
  "result": {
    "csv": "h1,a,c\nh2,b,d\n",
    "rows_in": 2,
    "cols_in": 2,
    "rows_out": 1,
    "cols_out": 3
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "csv-transpose",
  "version": "1.0.0",
  "input": {
    "csv": "h1,h2\na,b\nc,d\n"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/csv-transpose/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"csv":"h1,h2\na,b\nc,d\n"}'
```

The machine-readable contract is at [/v1/tools/csv-transpose/versions/1.0.0](/v1/tools/csv-transpose/versions/1.0.0).

### CLI

```sh
node cli.mjs run csv-transpose 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [CSV dedupe](/tools/csv-dedupe): Remove duplicate CSV data rows while preserving the first occurrence.
- [CSV group count](/tools/csv-group-count): Count CSV rows by exact named-column tuples in first-seen order.
- [CSV sort](/tools/csv-sort): Stably sort CSV rows by exact named string columns.
- [CSV to JSON](/tools/csv-to-json): Convert a complete CSV document into an array of string-valued objects.
- [CSV add row number](/tools/csv-add-row-number): Prepend a 1-based row_number column of canonical integer strings.
- [CSV anti join](/tools/csv-anti-join): Keep left CSV rows whose exact key tuples do not appear in the right document.
