I have a JSON data structure that looks like this:
{
tag: 'new-tag',
stream_subjects: [1, 2, 3]
}
My goal is to transform it into the following format:
{
tag: 'new-tag',
stream_subjects: [
{subject_id: 1},
{subject_id: 2},
{subject_id: 3}
]
}
I am looking to achieve this transformation using
Object.keys(data).forEach((k) => { }
. Can someone please guide me on how to accomplish this task?
Object.keys(params.data).forEach((k) => {
console.log(`${k} - ${params.data[k]}`);
if (typeof params.data[k] === 'object') {
temp[k] = {};
for (const innerKey in params.data[k]) {
temp[k].subject_id = params.data[k];
}
} else {
temp[k] = params.data[k];
}
console.log(temp);
});