ng-rich-json-csv-parser

Ngx-rich-json-csv-parser help you to convert JSON to CSV file and Download it in the .csv format.

Features

  1. Convert JSON to CSV
  2. Download JSON data in CSV format file.
  3. Insert serial number
  4. Customize CSV file Header text
  5. Sort the CSV file data based on Header text
  6. Customize CSV file name

License

MIT

Installation

Start by installing the Angular Rich JSON CSV Parser library from npm

npm i -s ngx-rich-json-csv-parser

Next, you’ll need to import the NgxRichJsonCsvParserModule module in your app’s module.

To download JSON data as a CSV file format, use downloadFile() function

this._ngxRichJsonCsvParserService.downloadFile(< your Serial Number Header Name>, < Sort Header list>, );

Argument Details

OrderNameTypeDetails
1JSON DataAn array of objectsJSON data which is used to convert into CSV
2Custom HeaderAn array of StringYou can provide custom csv header name, please note
number of element in this header array should be equal to
number of property in single JSON array object data
3isAutoGenerateSlNo(IsGenerateSerial Number)BooleanThis flag is used to generate Numerical serial number start from 1
4CSV File NamestringYour custom CSV file name
5Serial Number header namestringIf isAutoGenerateSlNo is true then you can provide custom header for Serial number
6Sort CSV Header listenumTo sort CSV Header list, available options are
– without Sorting : HeaderSortMode.NONE
– to sort ascending order: HeaderSortMode.ASC
– to sort descending order: HeaderSortMode.DESC
7Header Text formatenumTo format CSV all header text to uppercase or lowercase or capitalize or startcase(title case)
eg: HeaderCaseMode.StartCase

To convert JSON to CSV data format without downloading, use ConvertToCSV() function,

this._ngxRichJsonCsvParserService.ConvertToCSV(this.jsonData, [], true, ‘mySl’, HeaderSortMode.DESC, HeaderCaseMode.StartCase); // this function returns csv data

Argument details
OrderNameTypeDetails
1JSON DataAn array of objectsJSON data which is used to convert into CSV
2Custom HeaderAn array of StringYou can provide custom csv header name, please note
number of element in this header array should be equal to
number of property in single JSON array object data
3isAutoGenerateSlNo(IsGenerateSerial Number)BooleanThis flag is used to generate Numerical serial number start from 1
4Serial Number header namestringIf isAutoGenerateSlNo is true then you can provide custom header for Serial number
5Sort CSV Header listenumTo sort CSV Header list, available options are
– without Sorting : HeaderSortMode.NONE
– to sort ascending order: HeaderSortMode.ASC
– to sort descending order: HeaderSortMode.DESC
6Header Text formatenumTo format CSV all header text to uppercase or lowercase or capitalize or startcase(title case)
eg: HeaderCaseMode.StartCase

Github:

https://github.com/geekwebcast/ng-rich-json-csv-parser