---
schema_version: "1"
id: c347c899aabfdff99e5c93464e026425b2d9f434da8b821c432a3c126e903656
title: オブジェクト要素の配列としてのマップ
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.7/dataweave-cookbook-map-object-elements-as-an-array.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook-map-object-elements-as-an-array
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 6051f7c7e35fbf18377289cb5cd684daf3644b26ee96213241e6c3fd77144ca6
description: MuleSoft Documentation Site
release: "2.7"
latest: false
---
# オブジェクト要素の配列としてのマップ

この DataWeave の例では、DataWeave ​`map`​ 関数を使用して、キー ​`book`​ に一致するオブジェクト要素を反復処理します。入力には、無視されるキー ​`magazine`​ も含まれます。 開始する前に、Mule 4 アプリケーションでは DataWeave のバージョン 2.x が使用されることに注意してください。Mule 3 アプリケーションでの DataWeave については、​[DataWeave バージョン 1.2 の例](#1.2@dataweave::dataweave-examples.adoc)​を参照してください。 他の DataWeave バージョンの場合は、DataWeave の目次のバージョンセレクターを使用できます。

この例では、次の DataWeave 関数を使用します。

- キー ​`"book"`​ に一致する要素が含まれる配列を返す複数値セレクター ​`*book`​。
- 複数値セレクターによって返される配列の各オブジェクトを調べる ​`map`​。

DataWeave スクリプト:

```dataweave
%dw 2.0
var myInputExample = {
  "inventory": {
      "book" : {
        "category": "cooking",
        "title": "Everyday Italian",
        "author": "Giada De Laurentiis",
        "year": "2005",
        "price": "30.00"
      },
      "book" :{
        "category": "children",
        "title": "Harry Potter",
        "author": "J K. Rowling",
        "year": "2005",
        "price": "29.99"
      },
      "book" :{
        "category": "web",
        "title": "Learning XML",
        "author": "Erik T. Ray",
        "year": "2003",
        "price": "39.95"
      },
      "magazine" :{
        "category": "web",
        "title": "Wired Magazine",
        "edition": "03-2017",
        "price": "15.95"
      },
        "magazine" :{
        "category": "business",
        "title": "Time Magazine",
        "edition": "04-2017",
        "price": "17.95"
      }
   }
}
output application/json
---
items: myInputExample.inventory.*book map (item, index) -> {
      "theType": "book",
      "theID": index,
      "theCategory": item.category,
      "theTitle": item.title,
      "theAuthor": item.author,
      "theYear": item.year,
      "thePrice": item.price as Number
}
```

出力 JSON:

```json
{
  "items": [
    {
      "theType": "book",
      "theID": 0,
      "theCategory": "cooking",
      "theTitle": "Everyday Italian",
      "theAuthor": "Giada De Laurentiis",
      "theYear": "2005",
      "thePrice": 30.00
    },
    {
      "theType": "book",
      "theID": 1,
      "theCategory": "children",
      "theTitle": "Harry Potter",
      "theAuthor": "J K. Rowling",
      "theYear": "2005",
      "thePrice": 29.99
    },
    {
      "theType": "book",
      "theID": 2,
      "theCategory": "web",
      "theTitle": "Learning XML",
      "theAuthor": "Erik T. Ray",
      "theYear": "2003",
      "thePrice": 39.95
    }
  ]
}
```

## [](#関連する例)関連する例

- [DataWeave を使用したデータのマップ](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook-map)
- [オブジェクトのマップ](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook-map-an-object)
- [項目の除外](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook-exclude-field)
- [キーの名前の変更](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook-rename-keys)

## [](#関連情報)関連情報

- [DataWeave の型](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-types)
- [DataWeave セレクター](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-selectors)
- [DataWeave の解説書](https://docs.mulesoft.com/jp/dataweave/2.7/dataweave-cookbook)