---
schema_version: "1"
id: 934b68b3d5f3880148551beafb3cd55a2a9b251fa2b46d3885229f5318f29a54
title: Zip Arrays Together
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dataweave-cookbook-zip-arrays-together.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-zip-arrays-together
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 924398f7fda837bb0370d1ca4ed5a90c2c8ca610cc688b9de76bfd4e7721e773
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
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
---

# Zip Arrays Together

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

This DataWeave example restructures bills of materials for Ikea-style furniture. The input contains
the measurements and amounts of screws in two separate arrays that run in parallel, the
transformation reorders them so that the "screws" array is made up of tuples, each with a
measurement and its corresponding amount. The same is applied to wooden boards: the input contains
two arrays with the x and the y measurements of each; the transformation rearranges them into a
series of tuples, one for each board.

It uses these DataWeave functions:

- `map` to go through the elements in the main array.

- `zip` to rearrange pairs of long arrays, so that they’re grouped by index into multiple
  two-element arrays.

DataWeave Script:

```dataweave
%dw 2.0
output application/json
---
payload map (item, index) ->
{
    name: item.name,
    id: item.itemID,
    screws: zip(item.screws.size, item.screws.quantity),
    measurements: zip(item.measurements.x,item.measurements.y )
}
```

Input JSON Payload:

```json
[
  {
    "name": "wooden-chair",
    "itemID": "23665",
    "screws": {
      "size": [4, 6, 10],
      "quantity": [15, 8, 28]
    },
    "measurements": { "x": [25, 46, 46, 16, 150, 5, 100, 100, 8], "y": [15, 4, 4, 80, 3, 4, 4, 15] }
  },
  {
    "name": "coffee-table",
    "itemID": "14398",
    "screws": {
      "size": [3, 8, 10],
      "quantity": [8, 12, 20]
    },
    "measurements": {
      "x": [55, 48, 48, 48, 48, 30, 30, 30, 30],
      "y": [55, 40, 40, 40, 50, 4, 4, 4, 4]
    }
  }
]
```

Output JSON:

```json
[
  {
    "name": "wooden-chair",
    "id": "23665",
    "screws": [
      [4, 15],
      [6, 8],
      [10, 28]
    ],
    "measurements": [
      [25, 15],
      [46, 4],
      [46, 4],
      [16, 80],
      [150, 3],
      [5, 4],
      [100, 4],
      [100, 15]
    ]
  },
  {
    "name": "coffee-table",
    "id": "14398",
    "screws": [
      [3, 8],
      [8, 12],
      [10, 20]
    ],
    "measurements": [
      [55, 55],
      [48, 40],
      [48, 40],
      [48, 40],
      [48, 50],
      [30, 4],
      [30, 4],
      [30, 4],
      [30, 4]
    ]
  }
]
```

## Related Examples

- [Regroup Fields](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-regroup-fields)

- [Transform XML to JSON](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-perform-basic-transformation)

- [Define a Custom Addition Function](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-define-a-custom-addition-function)

- [Pick Top Elements](https://docs.mulesoft.com/dataweave/2.11/dataweave-cookbook-pick-top-elements)

## See Also

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

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

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