JavaScript function which converts JSON to CSV