Global

Methods

# asciiEncoding() → {object}

Set ASCII encoding for reading files

View Source index.js, line 181

Module context for method chaining

object

# base64Encoding() → {object}

Set Base64 encoding for reading files

View Source index.js, line 190

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 361

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' }]

# csvStringToJsonAsync(input, optionsopt) → {Promise.<Array.<object>>}

Parse a raw CSV string asynchronously and return parsed JSON objects.

Parameters:
Name Type Attributes Description
input string

CSV content as a string

options object <optional>

Configuration options

raw boolean <optional>

If true, treats input as CSV content

View Source index.js, line 288

Promise resolving to array of parsed objects

Promise.<Array.<object>>

# 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 374

If csvString is invalid

If CSV is malformed

If JSON generation fails

JSON stringified array of objects

string

# csvStringToJsonStringifiedAsync(input) → {Promise.<string>}

Parse a raw CSV string asynchronously and return a JSON string.

Parameters:
Name Type Description
input string

CSV content as a string

View Source index.js, line 298

Promise resolving to JSON string

Promise.<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 136

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 67

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 47

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 231

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');

# generateJsonFileFromCsvAsync(input, output) → {Promise.<void>}

Parse a CSV file asynchronously and write the parsed JSON to an output file.

Parameters:
Name Type Description
input string

Path to the input CSV file

output string

Path to the output JSON file

View Source index.js, line 309

Promise resolving when file is written

Promise.<void>

# 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 254

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);

# getJsonFromCsvAsync(input, options) → {Promise.<Array.<object>>}

Parse CSV file asynchronously and return parsed data as JSON array.

Parameters:
Name Type Description
input string

Path to file or CSV string

options object

Configuration options

raw boolean

If true, treats first param as CSV content; if false, reads from file

View Source index.js, line 276

If input is invalid

If file read fails

If CSV is malformed

Promise resolving to array of objects

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

# getJsonFromFileStreamingAsync(filePath) → {Promise.<Array.<object>>}

Parse CSV from a file path using streaming for memory-efficient processing.

Parameters:
Name Type Description
filePath string

Path to the CSV file

View Source index.js, line 345

If filePath is invalid

If file cannot be read

If CSV is malformed

Promise resolving to array of objects representing CSV rows

Promise.<Array.<object>>
Example
const csvToJson = require('convert-csv-to-json');
const data = await csvToJson.getJsonFromFileStreamingAsync('large.csv');
console.log(data);

# getJsonFromStreamAsync(stream) → {Promise.<Array.<object>>}

Parse CSV from a Readable stream and return parsed data as JSON array. Processes data in chunks for memory-efficient handling of large files.

Parameters:
Name Type Description
stream object

Node.js Readable stream containing CSV data

View Source index.js, line 328

If stream is invalid

If CSV is malformed

Promise resolving to array of objects representing CSV rows

Promise.<Array.<object>>
Example
const fs = require('fs');
const csvToJson = require('convert-csv-to-json');
const stream = fs.createReadStream('large.csv');
const data = await csvToJson.getJsonFromStreamAsync(stream);
console.log(data);

# hexEncoding() → {object}

Set Hex encoding for reading files

View Source index.js, line 199

Module context for method chaining

object

# ignoreColumnIndexes(indexes) → {object}

Set column indexes to ignore Specified columns will be excluded from the JSON output

Parameters:
Name Type Description
indexes Array.<number>

Array of column indexes to ignore

View Source index.js, line 119

Module context for method chaining

object
Example
csvToJson.ignoreColumnIndexes([1, 3]) // Ignore columns at index 1 and 3

# 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 90

Module context for method chaining

object

# latin1Encoding() → {object}

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

View Source index.js, line 172

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 215

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 106

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 58

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 79

Module context for method chaining

object

# ucs2Encoding() → {object}

Set UCS-2 encoding for reading files

View Source index.js, line 154

Module context for method chaining

object

# utf16leEncoding() → {object}

Set UTF-16 LE encoding for reading files

View Source index.js, line 163

Module context for method chaining

object

# utf8Encoding() → {object}

Set UTF-8 encoding (default encoding)

View Source index.js, line 145

Module context for method chaining

object