Class

BrowserApi

BrowserApi()

Browser-friendly CSV to JSON API Provides methods for parsing CSV strings and File/Blob objects in browser environments Proxies configuration to sync csvToJson instance

Constructor

# new BrowserApi()

Constructor initializes proxy to sync csvToJson instance

View Source src/browserApi.js, line 14

Methods

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

Parse a CSV string and return as JSON array of objects

Parameters:
Name Type Description
csvString string

CSV content as string

View Source src/browserApi.js, line 105

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.browser.csvStringToJson('name,age\nAlice,30');
console.log(rows); // [{ name: 'Alice', age: '30' }]

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

Parse a CSV string asynchronously (returns resolved Promise)

Parameters:
Name Type Description
csvString string

CSV content as string

View Source src/browserApi.js, line 151

If csvString is invalid

If CSV is malformed

Promise resolving to array of objects

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

# csvStringToJsonStringified(csvString) → {string}

Parse a CSV string and return as stringified JSON

Parameters:
Name Type Description
csvString string

CSV content as string

View Source src/browserApi.js, line 128

If csvString is invalid

If CSV is malformed

JSON stringified array of objects

string
Example
const csvToJson = require('convert-csv-to-json');
const jsonString = csvToJson.browser.csvStringToJsonStringified('name,age\nAlice,30');
console.log(jsonString);

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

Parse a CSV string asynchronously and return as stringified JSON

Parameters:
Name Type Description
csvString string

CSV content as string

View Source src/browserApi.js, line 166

If csvString is invalid

If CSV is malformed

Promise resolving to JSON stringified array

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

# fieldDelimiter(delimiter) → {this}

Set the field delimiter character

Parameters:
Name Type Description
delimiter string

Character(s) to use as field separator

View Source src/browserApi.js, line 48

For method chaining

this

# formatValueByType(active) → {this}

Enable or disable automatic type formatting for values

Parameters:
Name Type Default Description
active boolean true

Whether to format values by type (default: true)

View Source src/browserApi.js, line 28

For method chaining

this

# indexHeader(index) → {this}

Set the row index where CSV headers are located

Parameters:
Name Type Description
index number

Zero-based row index containing headers

View Source src/browserApi.js, line 68

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/browserApi.js, line 89

For method chaining

this

# parseFile(file, optionsopt) → {Promise.<Array.<object>>}

Parse a browser File or Blob object to JSON array.

Parameters:
Name Type Attributes Description
file File | Blob

File or Blob to read as text

options object <optional>

options: { encoding?: string }

View Source src/browserApi.js, line 181

Promise resolving to parsed JSON rows

Promise.<Array.<object>>
Example
const csvToJson = require('convert-csv-to-json');
const fileInput = document.querySelector('#csvfile').files[0];
const rows = await csvToJson.browser.parseFile(fileInput);
console.log(rows);

# 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/browserApi.js, line 79

For method chaining

this

# supportQuotedField(active) → {this}

Enable or disable support for RFC 4180 quoted fields

Parameters:
Name Type Default Description
active boolean false

Whether to support quoted fields (default: false)

View Source src/browserApi.js, line 38

For method chaining

this

# trimHeaderFieldWhiteSpace(active) → {this}

Configure whitespace handling in header field names

Parameters:
Name Type Default Description
active boolean false

If true, removes all whitespace; if false, only trims edges (default: false)

View Source src/browserApi.js, line 58

For method chaining

this