---
schema_version: "1"
id: 2cd856bb1979b6ae200a7e02f1dbc8a3808f2c67964d4255868e6e538c474417
title: mapObject
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.8/dw-core-functions-mapobject.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.8/dw-core-functions-mapobject
source_site: docs.mulesoft.com
content_type: documentation
content_hash: c8b380b2d1bb2ff4b9237a40fb66f063b259e17be71a39300acaa41643689be5
description: MuleSoft Documentation Site
release: "2.8"
latest: false
---
# mapObject

## [](#mapobject1)mapObject<K, V>(@StreamCapable object: { (K)?: V }, mapper: (value: V, key: K, index: Number) -> Object): Object

オブジェクトのキー、値、またはインデックスで動作するマッパーを使用して、オブジェクトを反復処理します。

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

<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>object</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>mapper</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">指定されたオブジェクトを出力オブジェクトにマップするために使用する ​<code>key</code>​、​<code>value</code>​、または ​<code>index</code>​ を提供する式またはセレクター。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、入力の ​`{ "a":"b","c":"d"}`​ を反復処理し、匿名マッパー関数 (​`(value,key,index) → { (index) : { (value):key} }`​) を使用して、指定された各オブジェクトのキーと値を反転し、オブジェクトのインデックスをキーとして返します。マッパーは名前付きパラメーターを使用して、入力オブジェクトのキー、値、インデックスを識別します。​`{"a":"b","c":"d"} mapObject { ($$$) : { ($):$$} }`​ のように、匿名パラメーターを使用して同じ式を記述することができます。

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

```DataWeave
%dw 2.0
output application/json
---
{"a":"b","c":"d"} mapObject (value,key,index) -> { (index) : { (value):key} }
```

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

```JSON
{ "0": { "b": "a" }, "1": { "d": "c" } }
```

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

次の例では、各価格に 5 を加え、常に小数点以下 2 桁が表示されるように数値に書式を設定します。

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

```DataWeave
%dw 2.0
output application/xml
---
{
    prices: payload.prices mapObject (value, key) -> {
        (key): (value + 5) as Number {format: "##.00"}
    }
}
```

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

```XML
<?xml version='1.0' encoding='UTF-8'?>
<prices>
    <basic>9.99</basic>
    <premium>53</premium>
    <vip>398.99</vip>
</prices>
```

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

```XML
<?xml version='1.0' encoding='UTF-8'?>
<prices>
  <basic>14.99</basic>
  <premium>58.00</premium>
  <vip>403.99</vip>
</prices>
```

## [](#mapobject2)mapObject(value: Null, mapper: (value: Nothing, key: Nothing, index: Nothing) -> Any): Null

`mapObject`​ を ​`null`​ 値に使用できるようにするヘルパー関数。

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

前述の例を使用して、​`mapObject`​ の入力が ​`null`​ の場合に出力結果も ​`null`​ であることをテストできます。XML では、​`null`​ 値は空のタグとして記述されます。この値は、ライタープロパティ ​`writeNilOnNull=true`​ を使用して変更できます。

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

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

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

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