1.1.0 • Public • Published


CSV to JSON converter is a lightweight and powerful utility that uses node.js to convert CSV files to JSON in an easy and customizable manner.


npm install @srihari_007/csv-to-json-converter


const csvtojson = require("@srihari_007/csv-to-json-converter");

// Convert a CSV file at the specified file path to a JSON object
const jsonFromFilePath = csvtojson().fromFilePath("/path/to/file.csv");

// Convert a CSV string to a JSON object
const jsonFromString = csvtojson().fromString(

// Convert a CSV array to a JSON object
const jsonFromArray = csvtojson().fromArray([

// Convert a CSV two-dimensional array to a JSON object
const jsonFromTwoDArray = csvtojson().fromTwoDimensonArray([
  ["header1", "header2"],
  ["value1", "value2"],
  ["value3", "value4"],

Error Handling

The csvtojson object has four methods: fromFilePath, fromString, fromArray, and fromTwoDimensonArray. If an error occurs while using one of these methods, an error will be thrown with a message indicating the cause of the error.

The possible error messages are:

  • Invalid file: The file specified by filePath is empty or contains only the headers.
  • Invalid path: The file specified by filePath does not exist.
  • Invalid file format: The file specified by filePath is not a CSV file.
  • Invalid syntax: The number of headers does not match the number of values in a row of the CSV file.


  • The fromFilePath method expects the file path to be specified as a string.
  • The fromString, fromArray, and fromTwoDimensonArray methods expect the CSV data to be in the form of a string, array, or two-dimensional array, respectively.
  • The first row of the CSV data is assumed to contain the headers.
  • The values in the JSON objects will be of the appropriate data type (e.g. numbers will be converted to numbers, True/False will be converted to boolean, strings will be left as strings).


The reason for this tool is that I was in charge of converting a couple of csv files to JSON and I couldn't find anything simple that did exactly what I expected. So I built this to be flexible enough for any file.


fw_qaq fw_qaq


csv-to-json-converter is released under the MIT license.


npm i @srihari_007/csv-to-json-converter

DownloadsWeekly Downloads






Unpacked Size

35.4 kB

Total Files


Last publish


  • srihari_007