I am new to programming and am working on a project that received a nested JSON response from an API using node.js. I am hoping to find a simple method to convert this JSON into a CSV for export. I have searched around a bit have tried jsonexport and nestedcsv2json packages, but I have not been able to get my format quite right and am unable to iterate though my JSON response.
Basically the JSON response is as follows:
{ '2016-01-31': { chats: 0, missed_chats: 5 },
'2016-02-01': { chats: 60, missed_chats: 7 },
'2016-02-02': { chats: 56, missed_chats: 1 },
'2016-02-03': { chats: 46, missed_chats: 0 },
'2016-02-04': { chats: 63, missed_chats: 2 },
'2016-02-05': { chats: 59, missed_chats: 4 },
'2016-02-06': { chats: 0, missed_chats: 1 } }
The issue I am having is that the size of this can vary depending on the date range that the user enters. So I will need to iterate through the returned dates and then extract the nested JSON. It could be one date or 100 dates.
I am looking to make a CSV format with headers that I can export:
Date Chats Missed Chats
2016-02-02 60 7
This should be quick and easy, but I am struggling to get this quite right. Any tips or help is greatly appreciated. Thanks!