I have a Json object coming from my api as:
{
"user1": ["report_dev", "report_test"],
"user2": ["output1", "output2", "output3", "output4"]
}
I want to convert this to this format:
[{ name: 'user1' }, { name: 'user2' }];
This must be simple enough but not sure about this. Do I have to loop through json and create custom one.
I tried with below code but this is not giving my expected result:
var array =[];
for (i in array1)
{
//array1 holds the json object
array.push('name', array1[i]]);
}
Thanks for looking into.
Updated:
details1:
user1: (2) ["report_dev", "report_test"]
user2: (4) ["output1", "output2", "output3", "output4"]
details2:
user1: (2) ["report_dev", "report_test"]
user2: (4) ["output1", "output2", "output3", "output4"]
Object.keys(array1).map(name => ({name}));, but can make your input a little clearer?