# Copy nested items to new array

**URL:** <https://forum.alumio.com/t/copy-nested-items-to-new-array/1054>\
**Category:** Data Transformers\
**Created:** [March 26, 2024, 12:21pm UTC](https://forum.alumio.com/t/copy-nested-items-to-new-array/1054 "2024-03-26T12:21:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![c.eggebeen](https://forum.alumio.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@c.eggebeen](https://forum.alumio.com/u/c.eggebeen)\
**Post date:** [March 26, 2024, 12:21pm UTC](https://forum.alumio.com/t/copy-nested-items-to-new-array/1054/1 "2024-03-26T12:21:14Z")

</div>

Hi,

I have the following issue:  
I have this JSON input:

```auto
{
    "products": {
        "10101702": {
            "sku": "10101702",
            "warehouse_products": {
                "warehouse_1": {
                    "warehouse_id": "warehouse_1",
                    "on_hand": 0,
                    "allocated": 0,
                    "backorder": 0,
                    "available": 0,
                    "non_sellable": 0
                },
                "warehouse_12": {
                    "warehouse_id": "warehouse_12",
                    "on_hand": 0,
                    "allocated": 0,
                    "backorder": 0,
                    "available": 0,
                    "non_sellable": 0
                }
            }
        },
        "10102402": {
            "sku": "10102402",
            "warehouse_products": {
                "warehouse_1": {
                    "warehouse_id": "warehouse_1",
                    "on_hand": 0,
                    "allocated": 0,
                    "backorder": 0,
                    "available": 0,
                    "non_sellable": 0
                }
            }
        },
        "10102503": {
            "sku": "10102503",
            "warehouse_products": {
                "warehouse_1": {
                    "warehouse_id": "warehouse_1",
                    "on_hand": 0,
                    "allocated": 0,
                    "backorder": 0,
                    "available": 0,
                    "non_sellable": 0
                }
            }
        }
    }
}

```

I want a output like this:

```auto
{
    "Inventroy": [
        {
            "warehouse_id": "warehouse_1",
            "on_hand": 0,
            "allocated": 0,
            "backorder": 0,
            "available": 0,
            "non_sellable": 0
        },
        {
            "warehouse_id": "warehouse_2",
            "on_hand": 0,
            "allocated": 0,
            "backorder": 0,
            "available": 0,
            "non_sellable": 0
        },
        {
            "warehouse_id": "warehouse_1",
            "on_hand": 0,
            "allocated": 0,
            "backorder": 0,
            "available": 0,
            "non_sellable": 0
        },
        {
            "warehouse_id": "warehouse_1",
            "on_hand": 0,
            "allocated": 0,
            "backorder": 0,
            "available": 0,
            "non_sellable": 0
        }
    ]
}

```

So loop over warehouse\_products in products and add all warehouse\_products childeren to a array.

Does anyone know how to do this?

@Gugi ?

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [March 26, 2024, 4:13pm UTC](https://forum.alumio.com/t/copy-nested-items-to-new-array/1054/2 "2024-03-26T16:13:41Z")

</div>

Hi @c.eggebeen

We can use [JMESPath](https://jmespath.org/) to achieve your objective. Give the below syntax a try.

```auto
&{products.*.warehouse_products.* | []}

```

---

<div class="post-metadata">

**Author:** ![c.eggebeen](https://forum.alumio.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@c.eggebeen](https://forum.alumio.com/u/c.eggebeen)\
**Post date:** [March 26, 2024, 7:03pm UTC](https://forum.alumio.com/t/copy-nested-items-to-new-array/1054/3 "2024-03-26T19:03:42Z")

</div>

Hi @Gugi,

Thanks, you’re amazing! Works perfectly

Kind regards,

Chris

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [March 27, 2024, 7:28am UTC](https://forum.alumio.com/t/copy-nested-items-to-new-array/1054/4 "2024-03-27T07:28:28Z")

</div>

Glad to hear that works. You can mark my reply above as the solution to your question 🙂

Feel free to read the article on how to [Use JMESPath to simplify your transformations](https://forum.alumio.com/t/use-jmespath-to-simplify-your-transformations/189) for other applications of JMESPath in transformers.
