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 follwing 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 follwing 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
- Routing in Angular JS using Angular UI Router
- Angular CLI | Angular Project Setup
- Angular 7 | Components
- Angular 7 | Installation
- Angular 7 | Introduction
- How to use jQuery in Angular ?
- Angular 7 | Architecture
- JSON web token | JWT
- Angular-JS ng-repeat Directive
- Difference between Angular and AngularJS
- AngularJS | json Filter
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.