Hi I am trying to transform a JSON data type from one format to another:
[ { name: 'CarNo', attributes: {}, children: [], content: '?' },
{ name: 'AccNo', attributes: {}, children: [], content: '?' },
{ name: 'SCS', attributes: {}, children: [], content: '?' }]
The target object would be based on the name property and the content property:
{'CarNo': '?', 'AccNo': '?', 'SCS': '?' }
I was thinking I could just reduce this but I am failing:
const filteredResponseObj = Object.keys(rawResponseBodyObj).reduce((p,c)=>{
if( c === 'name' ){
p[c]=rawResponseBodyObj[c].content;
}
return p;
},{});
What am I missing? clearly I have some issues with the reduction...