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

Convert JSON array to key-value object array with a fixed key name

shuo
New Contributor

Hi,

the input is an array of numbers:
[โ€œ324โ€,โ€œ1209โ€,โ€œ4849โ€,โ€œ2โ€]

then i want to transform them into an array like below:
[
{โ€œnumberโ€:โ€œ324โ€},
{โ€œnumberโ€:โ€œ1209โ€},
{โ€œnumberโ€:โ€œ4849โ€},
{โ€œnumberโ€:โ€œ2โ€}
]

I tried reduce() and also tried convert it to an object and then replace the key, but seems no luck for both.

Can anyone help with this transformation? thanks!

3 REPLIES 3

cjhoward18
Employee
Employee

Hi,

You can use this expression in a mapper:

["324","1209","4849","2"].map(val => {"number": val})

it works well! Thank you!

Hi @cjhoward18 ,
Thanks for the valuable suggestions, however, I need further help on the same lines:
I tried to use the same method in mapper snap which copied all node as is, How I can select a few of them. I need to have repetitive node โ€˜InvoiceLineโ€™ and need to select few fields after group by and change the name. The repetitive nodes should be like below screen:
image
and Iโ€™m using your suggestion as below screenshot:
image

Can you please suggest how to fix it?
Thanks,
Deepak Shaw.