Forum Discussion

shuo's avatar
shuo
New Contributor
4 years ago

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

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

  • mramaswamy's avatar
    mramaswamy
    New Contributor II

    Thanks for your reply. My root element was wrong. I was able to get this work by changing it.

    Thanks,
    Murugan