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

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

ID: `ndjson`

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

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

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

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

## [](#examples)例

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

- [例](#example1)
- [例](#example2)

### [](#example1)例

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

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

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

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

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

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

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

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

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

### [](#example2)例

次の例は、​`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 では、この形式の以下の設定プロパティがサポートされています。

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

この形式は、入力データを読み取るための指示を提供するプロパティを受け入れます。

<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>空の行を無視します。</p>
</div>
<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>無効なレコードをスキップし、この形式で有効でない値を無視します。</p>
</div>
<div class="paragraph">
<p>有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

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

この形式は、出力データを書き込むための指示を提供するプロパティを受け入れます。

<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>バッファライターのサイズ (バイト)。値は 8 よりも大きい必要があります。</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>​ に設定すると、出力をデータストリームとして生成し、スクリプトの実行は生成されたコンテンツがコンシュームされるまで延期されます。</p>
</div>
<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>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>ライターで出力に使用されるエンコード。デフォルトは「UTF-8」です。</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>null</code>​ 値をスキップします。デフォルトでは、スキップしません。</p>
</div>
<div class="ulist">
<ul>
<li>
<p><code>arrays</code><br>
JSON 出力の配列内の ​<code>null</code>​ 値を無視して除外します。たとえば、​<code>output application/x-ndjson skipNullOn="arrays"</code>​ のようにします。</p>
</li>
<li>
<p><code>objects</code><br>
値が ​<code>null</code>​ のキー-値ペア (例: <code>output application/x-ndjson skipNullOn="objects"</code>​) を無視します。</p>
</li>
<li>
<p><code>everywhere</code><br>
<code>skipNullOn</code>​ を配列とオブジェクトに適用します。たとえば、​<code>output application/x-ndjson skipNullOn="everywhere"</code>​ のようにします。</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>有効な値は ​<code>arrays</code>​、​<code>objects</code>​、​<code>everywhere</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>@</code>​ になります。</p>
</div>
<div class="paragraph">
<p>有効な値は、​<code>true</code>​ または ​<code>false</code>​ です。</p>
</div></div></td>
</tr>
</tbody>
</table>

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

この形式では、次の 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>