You just need a some knowledge about JSON. Nowadays JSON going very popular for process the data fast and easily.
Here is the sample code for generating the csv/excel file and follow the live preview at the end of the code.
See the live preview here on JSFIDDLE
Code reference from Convert JSON format to CSV format for MS Excel