cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Join two arrays , one array with same unique ID

JensDeveloper
Contributor II

Hi,

So I am trying to join two arrays, but one array contains multiple unique IDs and the other one not.
Let me explain below:
One array from sql select with these objects:
{
โ€œpersonidโ€: 433817,
โ€œcustomernumberโ€: 10796670,
โ€œfirstnameโ€: โ€œJensโ€,
โ€œlastnameโ€: โ€œLamโ€
}

The other sql select with an array of these object:
{
โ€œpersonidโ€: 433817,
โ€œcustomernumberโ€: 10796670,
โ€œmediaโ€: โ€œemailโ€,
โ€œmediaaddressโ€: โ€œinfo@tesla.deโ€
},
{
โ€œpersonidโ€: 433817,
โ€œcustomernumberโ€: 10796670,
โ€œmediaโ€: โ€œphoneโ€,
โ€œmediaaddressโ€:โ€œ0484848484โ€
}

Now I want to join them together based on PersonID, but it the second select you have multiple records with same personID and I want it to look like this :
{
โ€œpersonidโ€: 433817,
โ€œcustomernumberโ€: 10796670,
โ€œfirstnameโ€: โ€œJensโ€,
โ€œlastnameโ€: โ€œLamโ€
โ€œmediaโ€: โ€œemailโ€,
โ€œmediaaddressโ€: โ€œinfo@tesla.deโ€
โ€œmediaโ€: โ€œphoneโ€,
โ€œmediaaddressโ€:โ€œ0484848484โ€
}

Anyone know an solution, I found one that I use union and then groupby the field personID but that makes it complicater to get all the fields later in different etls.

Regards

Jens

1 ACCEPTED SOLUTION

Abhishek_Soni37
Contributor

@JensDeveloper , Itโ€™s correct that we canโ€™t have duplicate Keys in JSON object, You can use this mapper expression to achieve an array of contactInfo.
image
Test_Expression_2023_06_12.slp (4.3 KB)

I hope this helps. ๐Ÿ™‚

Cheers

View solution in original post

3 REPLIES 3

AleksandarAngel
Contributor III

Hi @JensDeveloper,

As I can see in the expected output you have an object with repeating keys, which is not possible in a JSON Object.

image

Let me know if this somehow helps.

BR,
Aleksandar.

Hi @AleksandarAngelevski ,

Aah yes , I see, I have found a way to add the rights fields to the array by using mapper expressions :).

Abhishek_Soni37
Contributor

@JensDeveloper , Itโ€™s correct that we canโ€™t have duplicate Keys in JSON object, You can use this mapper expression to achieve an array of contactInfo.
image
Test_Expression_2023_06_12.slp (4.3 KB)

I hope this helps. ๐Ÿ™‚

Cheers