---
schema_version: "1"
id: 8ed0d91285cabc05fd9288d4d8797205e0beb81b558f4309a53f1928b2de610a
title: Newline Delimited JSON (ndjson) Format
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dataweave-formats-ndjson.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dataweave-formats-ndjson
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 267a32ae9e4ef5e2803392fe0a59cd3d0e73dbdb47fbbe7301745691f402a8e9
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
keywords: format, ndjson, application/x-ndjson, application/x-ldjson, application/x-ndjson
---

# Newline Delimited JSON (ndjson) Format

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

MIME type: `application/x-ndjson`

ID: `ndjson`

DataWeave represents the Newline Delimited JSON format (ndjson) as an array of objects. Each line of
the ndjson format is mapped to one object in the array.

These parser strategies are supported by the ndjson reader:

- In-memory

- Streaming

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

## Examples

The following examples show uses of the ndjson format.

- [Example](#example1)

- [Example](#example2)

### Example

This example shows how DataWeave represents a simple ndjson input.

#### Input

```ndjson
{"name": "Leandro","lastName": "Shokida"}
{"name": "Mariano","lastName": "De Achaval"}
```

#### Source

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

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

#### Output

The DataWeave (dw) format outputs the ndjson input into an array of comma-separated objects.

```weave
[
    {"name": "Leandro","lastName": "Shokida"},
    {"name": "Mariano","lastName": "De Achaval"}
]
```

### Example

This example shows that the ndjson reader ignores all lines of ndjson data that are invalid if
`skipInvalid=true`.

#### Input

The input to the DataWeave source includes valid and invalid lines of ndjson data. Assume that the
input is from a file `myInput.ndjson`.

myInput.ndjson:

```ndjson
{"name": "Christian"
{"name": "Mariano"}
{"name": "Tomo"
{"name": "Shoki"}
```

#### Source

The DataWeave script inputs the contents of the input file `myInput.ndjson`, applies the
`skipInvalid=true` reader property, and transforms the input to the JSON format and MIME type.

```dataweave
%dw 2.0
var myInput = readUrl('classpath://myInput.ndjson', 'application/x-ndjson, {skipInvalid=true})
output application/json
---
myInput
```

#### Output

The JSON output is an array of the valid objects from the ndjson input.

```weave
[
  {
    "name": "Mariano"
  },
  {
    "name": "Shoki"
  }
]
```

## 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>ignoreEmptyLine</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>true</code></p></td><td><div><div><p>Ignores empty lines.</p></div><div><p>Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr><tr><td><p><code>skipInvalid</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Skips invalid records and ignores values that aren’t valid in this format.</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>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>'UTF-8'</code></p></td><td><div><div><p>Encoding that the writer uses for output. Defaults to "UTF-8".</p></div></div></td></tr><tr><td><p><code>skipNullOn</code></p></td><td><p><code>String</code></p></td><td><p><code>null</code></p></td><td><div><div><p>Skips <code>null</code> values. By default, DataWeave does not skip.</p></div><div><ul><li><p><code>arrays</code><br>Ignore and omit <code>null</code> values inside arrays from the JSON output, for example, with <code>output application/x-ndjson skipNullOn="arrays"</code>.</p></li><li><p><code>objects</code><br>Ignore key-value pairs that have <code>null</code> as the value, for example, with <code>output application/x-ndjson skipNullOn="objects"</code>.</p></li><li><p><code>everywhere</code><br>Apply <code>skipNullOn</code> to arrays and objects, for example, <code>output application/x-ndjson skipNullOn="everywhere"</code>.</p></li></ul></div><div><p>Valid values are <code>arrays</code> or <code>objects</code> or <code>everywhere</code>.</p></div></div></td></tr><tr><td><p><code>writeAttributes</code></p></td><td><p><code>Boolean</code></p></td><td><p><code>false</code></p></td><td><div><div><p>Converts attributes of a key into child key-value pairs of that key. The attribute key name starts with <code>@</code>.</p></div><div><p>Valid values are <code>true</code> or <code>false</code>.</p></div></div></td></tr></tbody></table>

## Supported MIME Types

This format supports these MIME types:

- `application/x-ndjson`

- `application/x-ldjson`
