Currently, I am facing an issue where I need to retrieve data from a database and export it to a CSV file. While I am able to fetch all the data successfully, I am encountering difficulty when trying to fetch data that is in object format as it shows up as "[object object]" in the CSV file.
TS file:
getData() {
let source = this.resultList;
let destination = [];
for (let i = 0; i < source.length; i++) {
let entry = new Entry();
entry.id = source[i]['id'];
entry.participantId = source[i]['participantId'];
entry.completedOn = moment(source[i]['completedOn']).format('DD/MM/YYYY');
if (typeof source[i]['satisfaction'] == 'string') {
entry['satisfaction'] = source[i]['satisfaction']
} else {
for (var property in source[i]['satisfaction']) {
if (source[i]['satisfaction'].hasOwnProperty(property)) {
entry[property] = source[i]['satisfaction'][property]
}
}
}
destination.push(entry);
}
return destination;
}
I am struggling to extract objects present in "prodandService" to the CSV file - they are being displayed as "[object object]" instead of the actual items.
JSON data:
{"satisfaction":{"prodandService":[{"index":"Orbiz"},{"index":"qwerq"},{"index":"asfd"},{"index":"test"},{"index":"test123"},{"index":"TestWD"},{"index":"IOS app"},{"index":"Lipstick"},{"index":"Foundation"},{"index":"lipstick"},{"index":"Website"},{"index":"App IOS"},{"index":"Shampoo Vanilla"},{"index":"Shampoo Strawberry"},{"index":"car"},"Lipstick"],"price":"medium","customer":"yes","recomondation":"4","sales":["phone"],"phoneVist":"3","importance":["Quality"],"frequence":"quarter","satisfaction":"3"},"completedOn":"2017-08-28T09:39:54.676Z","id":10,"participantId":217}
I would greatly appreciate any assistance with this issue.