# CSV module

The CSV module contains functions for reading and writing CSV data.

### Serialize

**Signature:** Serialize(input: sequence<{}>, delimiter: text) -> text&#x20;

Serialize the given sequence of records to CSV that uses the given delimiter character to separate the CSV fields. The resulting data will always contain a header line as it first line.

Fields containing may be escaped with double quotation character as specified in [RFC 4180](https://datatracker.ietf.org/doc/html/rfc4180).

Only sequences of records containing fields with [simple-types](https://docs.novacura.com/flow-connect/reference/reference/flowscript/walkthrough/simple-types "mention") (except binary) can be converted to CSV text. Using unsupported types in the serialization will return a empty text as its result.

```javascript
let test = [
    {"name": "Pancho", "age": 27}, 
    {"name": "Beatrix", "age": 66}
];

let csvData = CSV.Serialize(test, ","); // csvData has type text

return csvData
// Will generate the following data
//    name,age
//    Pancho,27
//    Beatrix,66
//
```

### Deserialize

**Signature:** Deserialize<**T**> (data: text, delimiter: text) -> T\*&#x20;

Deserialize the given CSV data using the specified delimiter into a sequence of records where the type of the record is specified by T. The deserialize function only supports CSV data where the first line is a header line containing a name that corresponds to each field in a line.&#x20;

```typescript
let test = "name,age\nPancho,27\nBeatrix,66"
type User = {
    name: text,
    age: number
}

let users = CSV.Deserialize<User>(test, ",");

return users
// Will return [
//    {"name": "Pancho", "age": 27}, 
//    {"name": "Beatrix", "age": 66}
// ];
```
