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 Convert CSV to JSON file having Comma Separated values in Node.js ?
- How to reset selected file with input tag file type in Angular 9?
- Routing in Angular JS using Angular UI Router
- Angular CLI | Angular Project Setup
- Angular 7 | Angular Data Services using Observable
- Adding Angular Material Component to Angular Application
- Difference between Angular 4 and Angular 5
- How to convert an array to CSV file in PHP ?
- How to download a CSV file in PHP that is triggered through a URL ?
- How to import data from .CSV file into MySQL table using Node.js ?
- Difference between node.js require and ES6 import and export
- PHP | ReflectionMethod export() Function
- PHP | ReflectionClass export() Function
- PHP | ReflectionExtension export() Function
- PHP | ReflectionFunction export() Function
- Node.js | Export Module
- ES6 | Import and Export
- Import and Export in Node.js
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