I have an array(arr) of objects where each object looks like this:-
{
"name" : "someName",
"address" : "someAddress",
"attributes" : [
{
"attName" : "Sea",
},
{
"attName" : "Beach",
}
],
"values" : [
"2540",
"3345",
"2340"
]
}
The arrays "values" and "attributes" may have different number of elements for different objects.
Now when I convert this array of objects to csv using this code:
const json2csv = require('json2csv').parse;
const csvString = json2csv(arr);
I get the following output:
name, address, attributes, values
"someName","someAddress", [{"attName" : "Sea"},{"attName" : "Beach"}], ["2540", "3345", "2340"]
However, I want my csv something like this:
name, address, attName, attName, value, value, value
"someName","someAddress", "Sea", "Beach", "2540", "3345", "2340"
I know that JSON doesn't allow multiple keys with same name but I can't figure out how to achieve this.