I am trying to export csv with headers but the condition is that I have 3 json. All 3 json are downloded in same csv file. Now I want to differentiate these json by including headers in csv file. I have a JSON like :
"data": {
"subData": [
[
{
"ABC": "North America",
"EFD": 937,
"EFDPercentage": 66.5483,
},
{
"ABC": "Europe",
"EFD": 123,
"EFDPercentage": 8.7358,
}
],
[
{
"PQR": "Media and Entertainment",
"topPQR": 174,
"PQRPercentage": 12.358,
},
{
"PQR": "Sep 2016",
"topPQR": 82,
"PQRPercentage": 5.8239,
},
{
"PQR": "Conference",
"topPQR": 50,
"PQRPercentage": 3.5511,
}
],
[
{
"XYZ": "M&E",
"topXYZ": 279,
"XYZPercentage": 19.8153,
},
{
"XYZ": "Technology",
"topXYZ": 197,
"XYZPercentage": 13.9915,
},
{
"XYZ": "Online Retail",
"topXYZ": 163,
"XYZPercentage": 11.5767,
}
]
]
}
As we know ng-csv attribute only accept only one json object. So that I have concatenate 3 object into one big object by doing this:
$scope.subDataArr = [];
$scope.subData = response.data.subData;
for(var i=0; i<self.subData.length; i++){
for(var j=0; j<self.subData[i].length; j++){
self.subDataArr.push(self.subData[i][j]);
}
}
So that all above data is merge into subDataArr in JSON object format. By accessing this object I can download all data into CSV file but I want to differentiate these data by giving headers in csv file. I know we are using csv-header to give heading in csv file. But here their are 3 different header list. So how can I use 3 different headers with their respective data? Please share your ideas. Thanks in advance.
I solve this problem. I create new object which have headers name and push into main json object which we are downloaded. Like this:
So all data with theirs headers are come into main JSON and I get expected output :-)