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

How to fetch values from below array?

Manigandan
New Contributor II

Hello Team,

I have my input coming like this,

[{โ€œ@propertyTypeKeyโ€:โ€œActive_Flagโ€,โ€œ@propertyTypeOwnerโ€:โ€œ4918โ€,โ€œvalueโ€:โ€œYโ€},

{โ€œ@propertyTypeKeyโ€:โ€œData_flagโ€,โ€œ@propertyTypeOwnerโ€:โ€œ4918โ€,โ€œvalueโ€:"N}]

I need to get my output like below,
โ€œActive_Flagโ€ = โ€œYโ€
โ€œData_flagโ€ = โ€œNโ€

Added above is a small example like this I have an big array from that i need to extract key and values as mentioned in the sample example. Could any of you please help me with this requirement.

1 ACCEPTED SOLUTION

viktor_n
Contributor II

Hi @Manigandan,

Use this expression
{array}.map(x => {[x[โ€˜@propertyTypeKeyโ€™]]: x.value})

Regards
Viktor

View solution in original post

4 REPLIES 4

viktor_n
Contributor II

Hi @Manigandan,

Use this expression
{array}.map(x => {[x[โ€˜@propertyTypeKeyโ€™]]: x.value})

Regards
Viktor

Manigandan
New Contributor II

Hello @viktor_n , you rock!!! It is working, thank you so much for the help!

Manigandan
New Contributor II

Hi @viktor_n and everyone,

When I tried the above expression.

I am getting response like below.

[{โ€œActive_Flagโ€: โ€œYโ€},{โ€œData_flagโ€:โ€œNโ€}, {โ€œidโ€:โ€œ1โ€} ]
[{โ€œActive_Flagโ€: โ€œNโ€},{โ€œData_flagโ€:โ€œYโ€}, {โ€œidโ€:โ€œ2โ€} ]

I wanted to flattened this records like below,

Id :1, Active_Flag: Y, Data_flag: N
Id :2, Active_Flag: N, Data_flag: Y

I tried json splitter it gives me whole array as flattened with no relation.

Can you please suggest me something.

thank you in advance!

For that to achieve, one approach is with the .reduce() function.

Add this function at the end of the existing expression.
.reduce((acc, curr) => acc.extend(curr), {})