---
schema_version: "1"
id: a7f9eb5d9bce64e45805def070837880adc1f41b9e4e6aad56774cbd7a3b375c
title: CSV Format
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dataweave-formats-csv.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dataweave-formats-csv
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 554b495639ac48e2867a369dbc1279e384bb2b47c0c688a975a067699c47584b
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
---

# CSV Format

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

MIME Type: `application/csv`

ID: `csv`

The CSV data format is represented as a DataWeave array of objects in which each object represents a
row. All simple values are represented as strings.

The DataWeave reader for CSV input supports the following parsing strategies:

- Indexed

- In-Memory

- Streaming

By default, the CSV reader stores input data from an entire file in-memory if the file is 1.5MB or
less. If the file is larger than 1.5 MB, the process writes the data to disk. For very large files,
you can improve the performance of the reader by setting a streaming property to true.

For additional details, see [DataWeave Readers](https://docs.mulesoft.com/dataweave/2.3/dataweave-formats#dw_readers_writers).

## Examples

The following examples show uses of the CSV format.

- [Example: Represent CSV Data](#example1)

- [Example: Stream CSV Data](#example2)

### Example: Represent CSV Data

The following example shows how DataWeave represents CSV data.

#### Input

The following sample data serves as input for the DataWeave source.

```csv
name,lastname,age,gender
Mariano,de Achaval,37,male
Paula,de Estrada,37,female
```

#### Source

The DataWeave script transforms the CSV input payload to the DataWeave (dw) format and MIME type.

```dataweave
%dw 2.0
output application/dw
---
payload
```

#### Output

The DataWeave script produces the following output.

```dataweave
[
  {
    name: "Mariano",
    lastname: "de Achaval",
    age: "37",
    gender: "male"
  },
  {
    name: "Paula",
    lastname: "de Estrada",
    age: "37",
    gender: "female"
  }
]
```

### Example: Stream CSV Data

By default, the CSV reader stores input data from an entire file in-memory if the file is 1.5MB or
less. If the file is larger than 1.5 MB, the process writes the data to disk. For very large files,
you can improve the performance of the reader by setting a `streaming` property to `true`. To
demonstrate the use of this property, the next example streams a CSV file and transforms it to JSON.

#### Input

The structure of the CSV input looks something like the following. Note that a streamed file is
typically much longer.

CSV File Input for Streaming Example (truncated):

```csv
street,city,zip,state,beds,baths,sale_date
3526 HIGH ST,SACRAMENTO,95838,CA,2,1,Wed May 21 00:00:00 EDT 2018
51 OMAHA CT,SACRAMENTO,95823,CA,3,1,Wed May 21 00:00:00 EDT 2018
2796 BRANCH ST,SACRAMENTO,95815,CA,2,1,Wed May 21 00:00:00 EDT 2018
2805 JANETTE WAY,SACRAMENTO,95815,CA,2,1,Wed May 21 00:00:00 EDT 2018
6001 MCMAHON DR,SACRAMENTO,95824,CA,2,1,,Wed May 21 00:00:00 EDT 2018
5828 PEPPERMILL CT,SACRAMENTO,95841,CA,3,1,Wed May 21 00:00:00 EDT 2018
```

#### XML Configuration

To demonstrate a use of the `streaming` property, the following Mule flow streams a CSV file and
transforms it to JSON.

```xml
<flow name="dw-streamingFlow" >
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <fixed-frequency frequency="1" timeUnit="MINUTES"/>
    </scheduling-strategy>
  </scheduler>
  <file:read
     path="${app.home}/input.csv"
     config-ref="File_Config"
     outputMimeType="application/csv; streaming=true; header=true"/>
  <ee:transform doc:name="Transform Message" >
    <ee:message >
      <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload map ((row) -> {
zipcode: row.zip
})]]></ee:set-payload>
    </ee:message>
  </ee:transform>
  <file:write doc:name="Write"
    config-ref="File_Config1"
    path="/path/to/output/file/output.json"/>
  <logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
```

- The example configures the Read operation (`<file:read/>`) to stream the CSV input by setting
  `outputMimeType="application/csv; streaming=true"`. The input CSV file is located in the project
  directory, `src/main/resources`, which is the location of `${app.home}`.

- The DataWeave script in the **Transform Message** component uses the `map` function to iterate
  over each row in the CSV payload and select the value of each field in the `zip` column.

- The Write operation returns a file, `output.json`, which contains the result of the
  transformation.

- The Logger prints the same output payload that you see in `output.json`.

#### Output

The CSV streaming example produces the following output.

```json
[
  {
    "zipcode": "95838"
  },
  {
    "zipcode": "95823"
  },
  {
    "zipcode": "95815"
  },
  {
    "zipcode": "95815"
  },
  {
    "zipcode": "95824"
  },
  {
    "zipcode": "95841"
  }
]
```

## Configuration Properties

DataWeave supports the following configuration properties for CSV.

### Reader Properties

The CSV format accepts properties that provide instructions for reading input data.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><p><code>bodyStartLineNumber</code></p></td><td><p><code>Number</code></p></td><td><p><code>0</code></p></td><td><div><div><p>The line number on which the body starts.</p></div></div></td></tr><tr><td><p><code>escape</code></p></td><td><p><code>String</code></p></td><td><p><code>\</code></p></td><td><div><div><p>Character used to escape invalid characters, such as separators or quotes within field values.</p></div></div></td></tr><tr><td><p><code>header</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>true</code></p></td><td><div><div><p>Indicates whether a CSV header is present. Valid values are <code>true</code> or <code>false</code>.</p></div><div><ul><li><p>If <code>header=true</code>, you can access the fields within the input by name, for example, <code>payload.userName</code>.</p></li><li><p>If <code>header=false</code>, you must access the fields by index, referencing the entry first and the field next, for example, <code>payload[107][2]</code>.</p></li></ul></div></div></td></tr><tr><td><p><code>headerLineNumber</code></p></td><td><p><code>Number</code></p></td><td><p><code>0</code></p></td><td><div><div><p>The line number on which the CSV header is located.</p></div></div></td></tr><tr><td><p><code>ignoreEmptyLine</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>true</code></p></td><td><div><div><p>Ignores any empty line. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>quote</code></p></td><td><p><code>String</code></p></td><td><p><code>"</code></p></td><td><div><div><p>Character to use for quotes.</p></div></div></td></tr><tr><td><p><code>separator</code></p></td><td><p><code>String</code></p></td><td><p><code>,</code></p></td><td><div><div><p>Character that separates one field from another field.</p></div></div></td></tr><tr><td><p><code>streaming</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Property for streaming CSV input. Use only if entries are accessed sequentially. Valid values are <code>true</code> or <code>false</code>. See the <a href="#example2">streaming example</a>, and see <a href="https://docs.mulesoft.com/dataweave/2.3/dataweave-formats#dw_readers_writers">DataWeave Readers</a>.</p></div></div></td></tr></tbody></table>

### Writer Properties

The CSV format accepts properties that provide instructions for writing output data.

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Type</th><th>Default</th><th>Description</th></tr></thead><tbody><tr><td><p><code>bodyStartLineNumber</code></p></td><td><p><code>Number</code></p></td><td><p><code>0</code></p></td><td><div><div><p>Line number on which the body starts.</p></div></div></td></tr><tr><td><p><code>bufferSize</code></p></td><td><p><code>Number</code></p></td><td><p><code>8192</code></p></td><td><div><div><p>Size of the writer buffer.</p></div></div></td></tr><tr><td><p><code>deferred</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>When set to <code>true</code>, DataWeave generates the output as a data stream, and the script’s execution is deferred until it is consumed. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>encoding</code></p></td><td><p><code>String</code></p></td><td><p><code>null</code></p></td><td><div><div><p>Encoding for the writer to use, such as <code>UTF-8</code>.</p></div></div></td></tr><tr><td><p><code>escape</code></p></td><td><p><code>String</code></p></td><td><p><code>\</code></p></td><td><div><div><p>Character to use for escaping an invalid character, such as occurrences of the separator or quotes within field values.</p></div></div></td></tr><tr><td><p><code>header</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>true</code></p></td><td><div><div><p>Indicates whether to write a CSV header. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>headerLineNumber</code></p></td><td><p><code>Number</code></p></td><td><p><code>0</code></p></td><td><div><div><p>Identifies the line number on which the header is located.</p></div></div></td></tr><tr><td><p><code>ignoreEmptyLine</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>true</code></p></td><td><div><div><p>Ignores any empty line. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>lineSeparator</code></p></td><td><p><code>String</code></p></td><td><p>New Line</p></td><td><div><div><p>Line separator to use when writing the CSV, for example, <code>\r\n</code>.</p></div></div></td></tr><tr><td><p><code>quote</code></p></td><td><p><code>String</code></p></td><td><p><code>"</code></p></td><td><div><div><p>The character to be used for quotes.</p></div></div></td></tr><tr><td><p><code>quoteHeader</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Indicates whether to quote header values. Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>quoteValues</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Indicates whether to quote every value (even if the value contains special characters). Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>separator</code></p></td><td><p><code>String</code></p></td><td><p><code>,</code></p></td><td><div><div><p>Character that separates one field from another field.</p></div></div></td></tr></tbody></table>

## Supported MIME Types

The CSV format supports the following MIME types.

<table><colgroup><col></colgroup><thead><tr><th>MIME Type</th></tr></thead><tbody><tr><td><p><code>*/csv</code></p></td></tr></tbody></table>
