---
schema_version: "1"
id: 14a63a19a81b0ebefa9e3893dbe113cef2b3b62da2341479fbd06b5a8e7691d3
title: CSV Format
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.6/dataweave-formats-csv.md
canonical_url: https://docs.mulesoft.com/dataweave/2.6/dataweave-formats-csv
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ff2c1872b19d9d382b53a9e8234030e135b41f1330a50bc70a91d050ebec921c
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
---
product: DataWeave
version: 2.6
keywords: format, csv, */csv, application/csv
---

# 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.6/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 this format.

### Reader Properties

This 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>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 to use for escaping special characters, such as separators or quotes.</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.</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><p>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>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>Indicates whether to ignore an empty line.</p></div><div><p>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>Streams input when set to <code>true</code>. Use only if entries are accessed sequentially. The input must be a top-level array. See the <a href="#example2">streaming example</a>, and see <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-formats#dw_readers_writers">DataWeave Readers</a>.</p></div><div><p>Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr></tbody></table>

### Writer Properties

This 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 buffer writer, in bytes. The value must be greater than <code>8</code>.</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>Generates the output as a data stream when set to <code>true</code>, and defers the script’s execution until the generated content is consumed.</p></div><div><p>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>The encoding to use for the output, such as UTF-8.</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 special characters, such as separators or quotes.</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.</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><p>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>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>Indicates whether to ignore an empty line.</p></div><div><p>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><code>New Line</code></p></td><td><div><div><p>Line separator to use when writing CSV, for example, <code>"\r\n"</code>. By default, DataWeave uses the system line separator.</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>quoteHeader</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Quotes header values when set to <code>true</code>.</p></div><div><p>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>Quotes every value when set to <code>true</code>, including values that contain special characters.</p></div><div><p>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

This 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>
