Class

CsvToJsonAsync

CsvToJsonAsync()

Asynchronous CSV to JSON converter Provides async file I/O methods and isolated parser configuration

Constructor

# new CsvToJsonAsync()

Constructor initializes proxy to sync csvToJson instance

View Source src/csvToJsonAsync.js, line 15

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 98

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 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 32

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 64

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 44

If file read fails

If CSV is malformed

JSON stringified array of objects

Promise.<string>

# async 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 src/csvToJsonAsync.js, line 153

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

# async 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 src/csvToJsonAsync.js, line 116

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