---
schema_version: "1"
id: 7cf18061337a523577f5c703a262b13d8f42d78cdca0f5029342deaa5b0e1eaf
title: read
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.6/dw-core-functions-read.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.6/dw-core-functions-read
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e9f8ef1a3bbd89c8419479f30227ecbccd3d02ac386d551f17f919d27aa761cd
description: MuleSoft Documentation Site
release: "2.6"
latest: false
---
# read

## [](#read1)read(stringToParse: String | Binary, contentType: String = "application/dw", readerProperties: Object = {}): Any

文字列またはバイナリを読み取り、解析後のコンテンツを返します。

この関数は、リーダーのデフォルトではコンテンツタイプを判別できない場合などに役立ちます。

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<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>stringToParse</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">読み取る文字列またはバイナリ。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>contentType</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">サポートされる形式 (またはコンテンツタイプ)。デフォルト: <code>application/dw</code>​。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>readerProperties</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">(省略可能) リーダー設定プロパティを定義します。他の形式およびリーダー設定プロパティについては、 <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-formats">「サポートされるデータ形式」</a>​を参照してください。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、JSON オブジェクト ​`{ "hello" : "world" }'`​ を読み取り、​`"application/json"`​ 引数を使用して​_入力_​コンテンツタイプを示します。対照的に、スクリプトのヘッダーの ​`output application/xml`​ ディレクティブでは、JSON コンテンツを XML 出力に変換するようにスクリプトに指示しています。XML 出力では、​`hello`​ がルート XML 要素として使用され、​`world`​ がその要素の値として使用されています。XML の ​`hello`​ は JSON オブジェクトのキー ​`"hello"`​ に対応し、​`world`​ は JSON 値 ​`"world"`​ に対応します。

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

```dw
%dw 2.0
output application/xml
---
read('{ "hello" : "world" }','application/json')
```

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

```JSON
<?xml version='1.0' encoding='UTF-8'?><hello>world</hello>
```

### [](#例-2)例

次の例では、文字列をヘッダーなしの CSV 形式として読み取り、JSON に変換します。列名がキーとして出力オブジェクトに追加されています。また、ここでは ​`[0]`​を関数コールに付加し、結果の配列の最初のインデックスを選択しているため、結果は配列内に生成されません (出力オブジェクト全体が角括弧で囲まれています)。

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

```DataWeave
%dw 2.0
var myVar = "Some, Body"
output application/json
---
read(myVar,"application/csv",{header:false})[0]
```

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

```JSON
{ "column_0": "Some", "column_1": " Body" }
```

### [](#例-3)例

次の例では、指定された XML を読み取り、リーダープロパティの構文 (この場合は ​`{ indexedReader: "false" }`​) を示しています。

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

```DataWeave
%dw 2.0
output application/xml
---
{
   "XML" : read("<prices><basic>9.99</basic></prices>",
                "application/xml",
                { indexedReader: "false" })."prices"
}
```

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

```XML
<?xml version='1.0' encoding='UTF-8'?>
<XML>
  <basic>9.99</basic>
</XML>
```