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
- How to read and write JSON file using Node.js ?
- Angular CLI | Angular Project Setup
- Routing in Angular JS using Angular UI Router
- PHP | ReflectionFunction export() Function
- PHP | ReflectionClass export() Function
- PHP | ReflectionExtension export() Function
- PHP | ReflectionMethod export() Function
- Angular 7 | Architecture
- How to use jQuery in Angular ?
- Angular 7 | Directives
- Angular 7 | Installation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai