

You can read and decode files with the following encoding: The property registered is printed as "registered": true If you want that a number will be printed as a Number type, and values true or false is printed as a boolean Type, use: csvToJson.formatValueByType().getJsonFromCsv(fileInputName) If the header is not on the first line you can define the header index like: csvToJson.indexHeader(3).getJsonFromCsv(fileInputName) Empty rowsĮmpty rows are ignored and not parsed.

To be able to parse correctly fields wrapped in quote, like the last_name in the first row in the following example: need to activate the support quoted fields feature: csvToJson.supportQuotedField(true).getJsonFromCsv(fileInputName) if your field delimiter is the comma, then: csvToJson.fieldDelimiter(',').getJsonFromCsv(fileInputName) Support Quoted Fields

In case your CSV file has defined another field delimiter you have to call the function fieldDelimiter(myDelimiter) and pass it as parameter the field delimiter.Į.g. As default the field delimiter is the semicolon ( ), this means that during the parsing when a semicolon ( ) is matched a new JSON entry is created. To generate the JSON Object with sub array from the above CSV example: csvToJson.parseSubArray('*',',').getJsonFromCsv('myInputFile.csv') Ī field delimiter is needed to split the parsed values. With the values diego,marek,dries you have to call the function parseSubArray(delimiter, separator). } Generate Object with sub array the above CSV example, to generate a JSON Object with properties that contains sub Array, like the property sons Let json = csvToJson.getJsonFromCsv("myInputFile.csv") Let fileOutputName = 'myOutputFile.json' ĬsvToJson.generateJsonFileFromCsv(fileInputName,fileOutputName) Generate Array of Object in JSON format let csvToJson = require('convert-csv-to-json') Install package on your machine $ npm install -g convert-csv-to-json Usage Generate JSON file let csvToJson = require('convert-csv-to-json') Install package in your package.json $ npm install convert-csv-to-json -save
