---
schema_version: "1"
id: b18a4984c3e363fdb6b6cfe803c86c4053edb8540e0deabefee6571a64c25962
title: 改行区切りの JSON 形式 (ndjson)
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.3/dataweave-formats-ndjson.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.3/dataweave-formats-ndjson
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d95abcd9ae61cf4a813e89e245b638d8ec85f10c0977a20225d22a4ababc11fe
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
# 改行区切りの JSON 形式 (ndjson)

MIME タイプ: `application/x-ndjson`​

ID: `ndjson`​

DataWeave では、改行区切りの JSON 形式 (ndjson) をオブジェクトの配列として表します。ndjson 形式の各行は、配列の 1 つのオブジェクトにマップされます。

次のパーサー戦略は、ndjson リーダーでサポートされています。

- メモリ内
- ストリーミング

詳細は、​[「DataWeave リーダー」](https://docs.mulesoft.com/jp/dataweave/2.3/dataweave-formats#dw_readers_writers)​を参照してください。

## [](#examples)例

次の例は、ndjson 形式の使用方法を示しています。

- [例: ndjson を DataWeave 形式 (dw) を変換する](#example1)​
- [例: `skipInvalid`​ を使用する](#example2)

### [](#example1)例: ndjson を DataWeave 形式 (dw) を変換する

次の例は、DataWeave で単純な ndjson 入力を表す方法を示しています。

#### [](#入力)入力

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

#### [](#ソース)ソース

この DataWeave スクリプトは、ndjson 入力を DataWeave (dw) 形式と MIME タイプに変換します。

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

#### [](#出力)出力

DataWeave (dw) 形式では、ndjson 入力をカンマ区切りオブジェクトの配列に出力します。

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

### [](#example2)例: `skipInvalid`​ を使用する

次の例は、​`skipInvalid=true`​ の場合に ndjson リーダーが無効な ndjson データのすべての行を無視することを示しています。

#### [](#入力-2)入力

DataWeave ソースへの入力には、ndjson データの有効な行と無効な行が含まれます。​`myInput.ndjson`​ ファイルから入力を取得することが前提となっています。

myInput.ndjson:

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

#### [](#ソース-2)ソース

この DataWeave スクリプトは、入力ファイル ​`myInput.ndjson`​ のコンテンツを入力し、​`skipInvalid=true`​ リーダープロパティを適用して、入力を JSON 形式と MIME タイプに変換します。

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

#### [](#出力-2)出力

この JSON 出力は、ndjson 入力の有効なオブジェクトの配列です。

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

## [](#properties)Configuration のプロパティ

DataWeave では、改行区切りの JSON 形式 (ndjson) の次の設定プロパティがサポートされています。

### [](#reader-のプロパティ)Reader のプロパティ

ndjson 形式では、入力データの読み込みの指示を提供するプロパティを使用できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 50.0002%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">型</th>
<th class="tableblock halign-left valign-top">デフォルト</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>ignoreEmptyLine</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>true</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>空の行を無視します。有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>skipInvalid</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>false</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>有効な ndjson でないデータをスキップします。有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

### [](#writer-のプロパティ)Writer のプロパティ

ndjson 形式では、出力データの書き込みの指示を提供するプロパティを使用できます。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 16.6666%;">
<col style="width: 50.0002%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">パラメーター</th>
<th class="tableblock halign-left valign-top">型</th>
<th class="tableblock halign-left valign-top">デフォルト</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>bufferSize</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>8192</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>ライターバッファのサイズ。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>deferred</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>false</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>​<code>true</code>​ に設定すると、DataWeave は出力をデータストリームとして生成し、スクリプトの実行はそれがコンシュームされるまで延期されます。有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>encoding</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>'UTF-8'</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>使用する ndjson リーダーのエンコード。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>skipNullOn</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>String</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>null</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>有効な値は、​<code>arrays</code>​ または ​<code>objects</code>​ です。</p>
</div></div></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>writeAttributes</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>Boolean</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">​<code>false</code></p></td>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p>有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

## [](#mime_type)サポートされる MIME タイプ

改行区切りの JSON 形式 (ndjson) では、次の MIME タイプがサポートされています。

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 100%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">MIME タイプ</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>application/x-ndjson</code>​</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>application/x-ldjson</code>​</p></td>
</tr>
</tbody>
</table>