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 reset selected file with input tag file type in Angular 9?
- Angular 7 | Angular Data Services using Observable
- Adding Angular Material Component to Angular Application
- Difference between Angular 4 and Angular 5
- Angular File Upload
- How to change the font of HTML5 Canvas using a button in Angular.js?
- How to use jQuery in Angular ?
- How to create button dynamically with click event in Angular ?
- Angular 7 | Directives
- What is the equivalent of ngShow and ngHide in Angular 2+?
- How to append Angular styles in footer ?
- What is the meaning of let-* in Angular 2 Templates ?
- Angular 7 | Observables
- Difference between Angular and jQuery
- Difference between Backbone.js and Angular.js
- How to use bootstrap 4 in angular 2?
- What are the differences between an Annotation and a Decorator in Angular?
- What is entryComponents in angular ngModule ?
- What is the use of Angular 2 hashtags in template ?
- How to create a To-Do list using Drag and Drop in Angular 7 ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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