# Combining / moving objects in an array based on product number

**URL:** <https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999>\
**Category:** Data Transformers\
**Tags:** best-practice, mappers, data-transformer\
**Created:** [February 21, 2024, 1:36pm UTC](https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999 "2024-02-21T13:36:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![j.wiegmann](https://forum.alumio.com/user_avatar/forum.alumio.com/j.wiegmann/32/1570_2.png) [@j.wiegmann](https://forum.alumio.com/u/j.wiegmann)\
**Post date:** [February 21, 2024, 1:36pm UTC](https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999/1 "2024-02-21T13:36:51Z")

</div>

Hi there,

I am trying to combine / move objects from a storage based on (a part of) the product number.

For example, this is my data:

```auto
{
  "products": {
    "1234_A01_P01": {
      "data": "productdata"
    },
    "1234_A02_P02": {
      "data": "productdata"
    },
    "1235_A02_TX": {
      "data": "productdata"
    },
    "1352_A06_PP": {
      "data": "productdata"
    },
    "1352_A01_PP": {
      "data": "productdata"
    }
  }
}

```

I want to create objects based on the part before the first “\_” and combine / move the existing objects into a nested one. The output should be this:

```auto
{
  "1234": {
    "1234_A01_P01": {
      "data": "productdata"
    },
    "1234_A02_P02": {
      "data": "productdata"
    }
  },
  "1235": {
    "1235_A02_TX": {
      "data": "productdata"
    }
  },
  "1352": {
    "1352_A06_PP": {
      "data": "productdata"
    },
    "1352_A01_PP": {
      "data": "productdata"
    }
  }
}

```

This way, all the objects that correspond to the first values before the “\_” are inside the same object.

---

<div class="post-metadata">

**Author:** ![catalin](https://forum.alumio.com/user_avatar/forum.alumio.com/catalin/32/1428_2.png) [@catalin](https://forum.alumio.com/u/catalin)\
**Post date:** [February 23, 2024, 8:44am UTC](https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999/2 "2024-02-23T08:44:59Z")

</div>

Hi @j.wiegmann welcome,

Yes, we have dealt with this type of logic.  
The solution to this one is a bit more complicated to explain directly…  
Long story short, you copy they keys inside themselves and format them accordingly.  
In you case, regex before the first “\_” to get the “1234” and so on.  
After that group them by the new result from above.  
Final result in Alumio looks like this

 ![image](https://alumio-forum.s3.dualstack.eu-central-1.amazonaws.com/uploads/original/2X/2/297c858699e40ca46744c88ac472aa5afe9d2c86.png)

---

<div class="post-metadata">

**Author:** ![catalin](https://forum.alumio.com/user_avatar/forum.alumio.com/catalin/32/1428_2.png) [@catalin](https://forum.alumio.com/u/catalin)\
**Post date:** [February 23, 2024, 8:45am UTC](https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999/3 "2024-02-23T08:45:41Z")

</div>

Transformer would be of much use to you to actually see the logic  
[export\_20240223104512.ndjson](https://forum.alumio.com/uploads/short-url/uai54M48Ns4Ux8YyWORpIJdJXIf.ndjson) (2.4 KB)

---

<div class="post-metadata">

**Author:** ![j.wiegmann](https://forum.alumio.com/user_avatar/forum.alumio.com/j.wiegmann/32/1570_2.png) [@j.wiegmann](https://forum.alumio.com/u/j.wiegmann)\
**Post date:** [February 23, 2024, 11:08am UTC](https://forum.alumio.com/t/combining-moving-objects-in-an-array-based-on-product-number/999/4 "2024-02-23T11:08:58Z")

</div>

Thanks @catalin, I imported the transformer and this works perfectly.
