I have some JSON which takes the following form.
[
[
{
"ID": 1,
"col1": "something",
"col2": "something"
},
{
"ID": 2,
"col1": "something",
"col2": "something"
}
],
[
{
"ID": 1,
"col3": "something else"
},
{
"ID": 2,
"col3": "something else"
}
]
]
Using D3, I parse this JSON into an multidimensional array. I am then preparing the data for download as a CSV. So at the moment, I am doing
let csvData = 'ID,col1,col2\n';
data[0].forEach(function(row) {
let line = [];
Object.keys(row).forEach(function(key) {
line.push(row[key])
});
csvData = csvData + line.join(',') + '\n';
});
The above will produce a flat csv file like so
id,col1,col2
1,something,something
2,something,something
What I am trying to do now is add the match up the id in the next array element, and add col3 to the data. So the overall output of the csvData should be
id,col1,col2,col3
1,something,something,something else
2,something,something,something else
How can I add this data to my existing csvData?
Thanks