---
schema_version: "1"
id: a3220a373b799e969b505c2d708462d4faf4775b450b8fbed8587650c7849469
title: Map Object Elements as an Array
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dataweave-cookbook-map-object-elements-as-an-array.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-map-object-elements-as-an-array
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0b29f72e814d48428501b2b6e305323035e14ae60051139f03163c12981d76f3
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
keywords: studio, anypoint, transform, transformer, format, aggregate, rename, split, filter convert, json, metadata, dataweave, data weave, datamapper, dwl, dfl, dw, output structure, input structure, map, mapping, as
---

# Map Object Elements as an Array

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

This DataWeave example uses the DataWeave `map` function to iterate through the object elements that
match the key `book`. The input also includes the key `magazine`, which is ignored.

The example uses these DataWeave functions:

- The multi-value selector `*book` to return an array with the elements that match the key `"book"`.

- `map` to go through each object in the array that’s returned by the multi-value selector.

DataWeave Script:

```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
}
```

Output JSON:

```json
{
  "items": [
    {
      "theType": "book",
      "theID": 0,
      "theCategory": "cooking",
      "theTitle": "Everyday Italian",
      "theAuthor": "Giada De Laurentiis",
      "theYear": "2005",
      "thePrice": 30.0
    },
    {
      "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
    }
  ]
}
```

## Related Examples

- [Map Data with DataWeave](https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-map)

- [Map an Object](https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-map-an-object)

- [Exclude Field](https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-exclude-field)

- [Rename Keys](https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-rename-keys)

## See Also

- [DataWeave Types](https://docs.mulesoft.com/dataweave/2.3/dataweave-types)

- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/2.3/dataweave-selectors)

- [DataWeave Cookbook](https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook)
