---
id: codecs--csv-decoder-plugin
title: "CSV decoder"
summary: "Splits CSV text into records: every line becomes one record of a flow type generated from the configured header names, all properties being strings. Input is a text record or a file stream."
audience: user
keywords: "input, output, continue, headers, encoding, firstlineisheaders, columnseparator, lineseparator, usequotes, quotecharacters, skipemptylines, trimstrategy, outputtypename, batchmode"
---
# CSV decoder

Splits CSV text into records: every line becomes one record of a flow type generated from the configured header names, all properties being strings. Input is a text record or a file stream.

## Pins

| Pin | Kind | Types | Description |
|---|---|---|---|
| Input | input | `Viaducta.Plugins.TextPlugin.Types.TextRecord`, `Viaducta.Plugins.Files.Types.ViaFileStream` | CSV content (`TextRecord.Value` or the stream). |
| Output | output | generated `<flow namespace>.<OutputTypeName>` | Called once per decoded line. |
| Continue | continue output | any (the input) | Called with the input after all lines are decoded. |

## Configuration

| Field | Type | Default | Description |
|---|---|---|---|
| `Headers` | string | | Required. Property names, comma-separated without spaces (`Id,Name,Price`). Each must be a valid identifier. Triggers reconfigure. |
| `Encoding` | dropdown: `UTF8`, `UTF7`, `UTF32`, `ASCII` | `UTF8` | Encoding of stream input. |
| `FirstLineIsHeaders` | boolean | `false` | `true` skips the first line. |
| `ColumnSeparator` | string | `,` | Column separator, may be several characters; escapes like `\t` are allowed. |
| `LineSeparator` | string | `\n` | Line separator with escapes (`\n`, `\r\n`). |
| `UseQuotes` | boolean | `true` | `true` recognizes quoted values; `false` reads quote characters as ordinary text. |
| `QuoteCharacters` | string | `"` | Quote character; only the first character is used. A doubled quote inside a quoted value is an escaped quote. |
| `SkipEmptyLines` | boolean | `true` | `true` ignores empty lines; `false` emits them as records with empty values. |
| `TrimStrategy` | dropdown: `0` None, `1` Start, `2` End, `3` StartAndEnd | `0` | Trimming of spaces and tabs around values (see Notes). |
| `OutputTypeName` | string (identifier) | | Required. Name of the generated record type. |
| `BatchMode` | dropdown: `1` Auto, `2` Always, `3` Never | `1` | Whether the records decoded from one input form a batch for batch consumers (Write file, Bulk insert, Build array, ...). `Auto`: only if the input is not already in a batch; inside a batch (e.g. a file read by Read file) the records stay in that batch. `Always`: a child batch per input (label = file or text record name). `Never`: no batch. |

## Behaviour

- Reconfigure (changing `Headers`) creates the type `OutputTypeName` in the flow namespace with one `String` property per header, in header order, and sets it on `Output`. Set `OutputTypeName` first: changing it alone does not regenerate the type; edit `Headers` again afterwards.
- Values are assigned by position: column 1 to the first header, and so on. Extra columns are ignored, missing ones stay `null`. Header names in the file are not used for mapping.
- One output record per line. When a batch is opened (`BatchMode`) it ends after the last record was processed downstream: consumers commit then; an error that reaches the decoder fails the batch.
- After the last line (and the batch end) `Continue` is called with the input.

## Notes

- Lines are split before quotes are evaluated: a line separator inside a quoted value breaks the record.
- `TrimStrategy` `1` (Start) trims both ends and `2` (End) trims nothing; use `3` for both ends.
- With `LineSeparator` `\n` on Windows files the last column keeps a trailing `\r` (trimming only removes spaces and tabs); use `\r\n` for such files.
- Header names must not contain spaces after commas (`Id, Name` fails validation).
- Whole input is loaded into memory; for memory streams the internal buffer is read, which may contain unused bytes after the content.
- All values are strings; convert types with a *Data mapper*.

## Example

```json
{ "Headers": "Id,Name,Price", "OutputTypeName": "PriceRow", "FirstLineIsHeaders": true, "ColumnSeparator": ";", "LineSeparator": "\\r\\n", "TrimStrategy": 3 }
```

File reader → **CSV decoder** → Data mapper → Table writer
