Global

Members

# constant csvToJsonAsync

Parse CSV file asynchronously and return parsed data as JSON array

View Source index.js, line 254

Example
const csvToJson = require('convert-csv-to-json');
const data = await csvToJson.getJsonFromCsvAsync('resource/input.csv');
console.log(data);

Methods

# asciiEncoding() → {object}

Set ASCII encoding for reading files

View Source index.js, line 155

Module context for method chaining

object

# base64Encoding() → {object}

Set Base64 encoding for reading files

View Source index.js, line 165

Module context for method chaining

object

# csvStringToJson(csvString) → {Array.<object>}

Parse a CSV string and return as JSON array of objects (synchronous)

Parameters:
Name Type Description
csvString string

CSV content as string

View Source index.js, line 284

If csvString is invalid

If CSV is malformed

Array of objects representing CSV rows

Array.<object>
Example
const csvToJson = require('convert-csv-to-json');
const rows = csvToJson.csvStringToJson('name,age\nAlice,30');
console.log(rows); // [{ name: 'Alice', age: '30' }]

# csvStringToJsonStringified(csvString) → {string}

Parse CSV string and return as stringified JSON (synchronous)

Parameters:
Name Type Description
csvString string

CSV content as string

View Source index.js, line 297

If csvString is invalid

If CSV is malformed

If JSON generation fails

JSON stringified array of objects

string

# customEncoding(encoding) → {object}

Set custom file encoding for reading CSV files Useful for non-UTF8 encoded files

Parameters:
Name Type Description
encoding string

Node.js supported encoding (e.g., 'utf8', 'latin1', 'ascii')

View Source index.js, line 105

Module context for method chaining

object

# fieldDelimiter(delimiter) → {object}

Set the field delimiter character used to separate CSV fields

Parameters:
Name Type Description
delimiter string

Character(s) to use as field separator (default: ',')

View Source index.js, line 51

Module context for method chaining

object

# formatValueByType(active) → {object}

Enable or disable automatic type formatting for values Converts numeric strings to numbers, 'true'/'false' to booleans

Parameters:
Name Type Description
active boolean

Whether to format values by type (default: true)

View Source index.js, line 29

Module context for method chaining

object

# generateJsonFileFromCsv(inputFileName, outputFileName)

Parse CSV file and write the parsed JSON to an output file (synchronous)

Parameters:
Name Type Description
inputFileName string

Path to input CSV file

outputFileName string

Path to output JSON file

View Source index.js, line 209

If inputFileName or outputFileName is not defined

Error

If file operations fail

If CSV is malformed

Example
const csvToJson = require('convert-csv-to-json');
csvToJson.generateJsonFileFromCsv('input.csv', 'output.json');

# getJsonFromCsv(inputFileName) → {Array.<object>}

Parse CSV file and return parsed data as JSON array of objects (synchronous)

Parameters:
Name Type Description
inputFileName string

Path to input CSV file

View Source index.js, line 232

If inputFileName is not defined

Error

If file read fails

If CSV is malformed

Array of objects representing CSV rows

Array.<object>
Example
const csvToJson = require('convert-csv-to-json');
const rows = csvToJson.getJsonFromCsv('resource/input.csv');
console.log(rows);

# hexEncoding() → {object}

Set Hex encoding for reading files

View Source index.js, line 175

Module context for method chaining

object

# indexHeader(index) → {object}

Set the row index where CSV headers are located Use this if headers are not on the first line (row 0)

Parameters:
Name Type Description
index number

Zero-based row index containing headers

View Source index.js, line 76

Module context for method chaining

object

# latin1Encoding() → {object}

Set Latin-1 (ISO-8859-1) encoding for reading files

View Source index.js, line 145

Module context for method chaining

object

# mapRows(mapperFn) → {object}

Set a mapper function to transform each row after conversion The mapper function receives (row, index) where row is the JSON object and index is the 0-based row number. Return null/undefined to filter out rows.

Parameters:
Name Type Description
mapperFn function

Function to transform each row

View Source index.js, line 192

Module context for method chaining

object
Example
csvToJson
  .mapRows((row, idx) => idx % 2 === 0 ? row : null) // Keep every other row
  .getJsonFromCsv('input.csv')

# parseSubArray(delimiter, separator) → {object}

Configure sub-array parsing for special field values Fields bracketed by delimiter and containing separator are parsed into arrays

Parameters:
Name Type Description
delimiter string

Bracket character (default: '*')

separator string

Item separator within brackets (default: ',')

View Source index.js, line 93

Module context for method chaining

object
Example
// Input field: "*val1,val2,val3*"
// Output array: ["val1", "val2", "val3"]
csvToJson.parseSubArray('*', ',')

# supportQuotedField(active) → {object}

Enable or disable support for RFC 4180 quoted fields When enabled, fields wrapped in double quotes can contain delimiters and newlines

Parameters:
Name Type Description
active boolean

Whether to support quoted fields (default: false)

View Source index.js, line 41

Module context for method chaining

object

# trimHeaderFieldWhiteSpace(active) → {object}

Configure whitespace handling in CSV header field names When active, removes all whitespace from header names (e.g., "My Name" → "MyName") When inactive, only trims leading and trailing whitespace

Parameters:
Name Type Description
active boolean

Whether to remove all whitespace from headers (default: false)

View Source index.js, line 64

Module context for method chaining

object

# ucs2Encoding() → {object}

Set UCS-2 encoding for reading files

View Source index.js, line 125

Module context for method chaining

object

# utf16leEncoding() → {object}

Set UTF-16 LE encoding for reading files

View Source index.js, line 135

Module context for method chaining

object

# utf8Encoding() → {object}

Set UTF-8 encoding (default encoding)

View Source index.js, line 115

Module context for method chaining

object