In this Article, we will learn How to convert a JSON array into CSV and How to Export CSV as a downloadable file by using Blob in angular 8.
Step1: Converting JSON to CSV
For converting JSON data in to CSV format use the following method.
The first parameter is Array of Objects, and second parameter is the headers List generally the keys of Json.
Step2: Exporting CSV as a downloadable file.
For exporting CSV data as a .csv file use the following method.
The download method accepts two parameters, the first parameter in JSONdata and the second parameter is filename. the default file name here is data. In the downloadFile method we are calling ConvertToCSV method which converts the JSON to CSV.
app.service.ts: Create a new service file with name app.component.ts
Now we have our service file, use this service file in our component to send the data and check whether our downloadFile method is properly working or not. Before creating component, first import our service in app.module.ts
Output: app.component.html file