---
schema_version: "1"
id: b2c331bb5365232047402a50f9305294650c090af54d818e902d6aed5bd3e078
title: writeLinesWith
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.4/dw-binaries-functions-writelineswith.md
canonical_url: https://docs.mulesoft.com/dataweave/2.4/dw-binaries-functions-writelineswith
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 78d66585afb18b50a96d5bed16ea24a88fb27c4d8f32045da0a92130b0da524f
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
---
product: DataWeave
version: 2.4
---

# writeLinesWith

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

## writeLinesWith(content: Array<String>, charset: String): Binary

Writes the specified lines and returns the binary content.

_Introduced in DataWeave version 2.2.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>content</code></p></td><td><p>Array of items to write.</p></td></tr><tr><td><p><code>charset</code></p></td><td><p>String representing the encoding to use when writing.</p></td></tr></tbody></table>

### Example

This example inserts a new line (`\n`) after each iteration. Specifically, it uses `map` to iterate
over the result of `to(1, 10)`, `[1,2,3,4,5]`, then writes the specified content ("Line
$"), which includes the unnamed variable `$` for each number in the array.

Note that without `writeLinesWith "UTF-8"`, the expression `{ lines: to(1, 10) map "Line $" }`
simply returns an array of line numbers as the value of an object:
`{ "lines": [ "line 1", "line 2", "line 3", "line 4", "line 5" ] }`.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Binaries
output application/json
---
{ lines: to(1, 10) map "Line $" writeLinesWith  "UTF-8" }
```

#### Output

```JSON
{
  "lines": "Line 1\nLine 2\nLine 3\nLine 4\nLine 5\n"
}
```
