---
schema_version: "1"
id: 55d250b0a4357c44d52ed78a6cce559b6d912eb5ac09a70450140620c9f47f6b
title: Zip Arrays Together
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dataweave-cookbook-zip-arrays-together.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dataweave-cookbook-zip-arrays-together
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 59ee3ca47fb520aab7d00ea3f7e171b4ea2c1861fe58830537db27c17288e471
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
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/latest/dataweave-cookbook-regroup-fields)

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

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

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

## See Also

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

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

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