Class

CsvToJsonAsync

CsvToJsonAsync()

Asynchronous CSV to JSON converter Proxies configuration to sync instance but provides async file I/O methods

Constructor

# new CsvToJsonAsync()

Constructor initializes proxy to sync csvToJson instance

View Source src/csvToJsonAsync.js, line 13

Methods

# csvStringToJsonAsync(csvString, options) → {Promise.<Array.<object>>}

Parse CSV string to JSON array (async)

Parameters:
Name Type Description
csvString string

CSV content as string

options object

Configuration options (default: { raw: true })

View Source src/csvToJsonAsync.js, line 175

If CSV is malformed

Array of objects representing CSV rows

Promise.<Array.<object>>
Example
const csvToJson = require('convert-csv-to-json');
const data = await csvToJson.csvStringToJsonAsync('name,age\nAlice,30');
console.log(data);

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

Parse CSV string to stringified JSON (async)

Parameters:
Name Type Description
csvString string

CSV content as string

View Source src/csvToJsonAsync.js, line 189

If CSV is malformed

JSON stringified array of objects

Promise.<string>
Example
const csvToJson = require('convert-csv-to-json');
const jsonString = await csvToJson.csvStringToJsonStringifiedAsync('name,age\nAlice,30');
console.log(jsonString);

# encoding(encoding) → {this}

Set file encoding for reading CSV files

Parameters:
Name Type Description
encoding string

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

View Source src/csvToJsonAsync.js, line 98

For method chaining

this

# fieldDelimiter(delimiter) → {this}

Set the field delimiter character

Parameters:
Name Type Description
delimiter string

Character(s) to use as field separator

View Source src/csvToJsonAsync.js, line 47

For method chaining

this

# formatValueByType(active) → {this}

Enable or disable automatic type formatting for values

Parameters:
Name Type Description
active boolean

Whether to format values by type

View Source src/csvToJsonAsync.js, line 27

For method chaining

this

# async generateJsonFileFromCsv(fileInputName, fileOutputName) → {Promise.<void>}

Read a CSV file and write parsed JSON to an output file (async)

Parameters:
Name Type Description
fileInputName string

Path to input CSV file

fileOutputName string

Path to output JSON file

View Source src/csvToJsonAsync.js, line 111

If file operations fail

If CSV is malformed

Promise.<void>

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

Main async API method for reading CSV and returning parsed JSON Supports reading from file path or parsing CSV string content

Parameters:
Name Type Description
inputFileNameOrCsv string

File path or CSV string content

options object

Configuration options

raw boolean

If true, treats input as CSV string; if false, reads from file

View Source src/csvToJsonAsync.js, line 143

If input is invalid

If file read fails

If CSV is malformed

Array of objects representing CSV rows

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

# async getJsonFromCsvStringified(fileInputName) → {Promise.<string>}

Read a CSV file and return parsed data as stringified JSON (async)

Parameters:
Name Type Description
fileInputName string

Path to input CSV file

View Source src/csvToJsonAsync.js, line 123

If file read fails

If CSV is malformed

JSON stringified array of objects

Promise.<string>

# indexHeader(indexHeader) → {this}

Set the row index where CSV headers are located

Parameters:
Name Type Description
indexHeader number

Zero-based row index containing headers

View Source src/csvToJsonAsync.js, line 67

For method chaining

this

# mapRows(mapperFn) → {this}

Set a mapper function to transform each row after conversion

Parameters:
Name Type Description
mapperFn function

Function receiving (row, index) that returns transformed row or null to filter

View Source src/csvToJsonAsync.js, line 88

For method chaining

this

# parseSubArray(delimiter, separator) → {this}

Configure sub-array parsing for special field values

Parameters:
Name Type Default Description
delimiter string *

Bracket character (default: '*')

separator string ,

Item separator within brackets (default: ',')

View Source src/csvToJsonAsync.js, line 78

For method chaining

this

# supportQuotedField(active) → {this}

Enable or disable support for RFC 4180 quoted fields

Parameters:
Name Type Description
active boolean

Whether to support quoted fields

View Source src/csvToJsonAsync.js, line 37

For method chaining

this

# trimHeaderFieldWhiteSpace(active) → {this}

Configure whitespace handling in header field names

Parameters:
Name Type Description
active boolean

If true, removes all whitespace; if false, only trims edges

View Source src/csvToJsonAsync.js, line 57

For method chaining

this