Class

BrowserApi

BrowserApi()

Browser-friendly CSV to JSON API Provides methods for parsing CSV strings and File/Blob objects in browser environments Uses isolated parser configuration via ParserConfig snapshots

Constructor

# new BrowserApi()

Constructor initializes proxy to sync csvToJson instance

View Source src/browserApi.js, line 16

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 65

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 98

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 81

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 113

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

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

Parse CSV from a File object using streaming for memory-efficient processing

Parameters:
Name Type Description
file File

File object containing CSV data

View Source src/browserApi.js, line 210

If file is invalid

If streaming is not supported or parsing fails

Promise resolving to array of objects representing CSV rows

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

# async getJsonFromFileStreamingAsyncWithCallback(file, options) → {Promise.<void>}

Parse CSV from a File object using streaming with progress callbacks for large files Processes data in chunks to avoid memory issues with large datasets

Parameters:
Name Type Attributes Description
file File

File object containing CSV data

options object

Processing options

onChunk function

Callback for each chunk of processed rows

onComplete function <optional>

Callback when processing is complete

onError function <optional>

Callback for errors

chunkSize number <optional>

Number of rows per chunk (default: 1000)

View Source src/browserApi.js, line 260

If file or options are invalid

Promise that resolves when streaming starts

Promise.<void>
Example
const csvToJson = require('convert-csv-to-json');
const fileInput = document.querySelector('#csvfile').files[0];

await csvToJson.browser.getJsonFromFileStreamingAsyncWithCallback(fileInput, {
  chunkSize: 500,
  onChunk: (rows, processed, total) => {
    console.log(`Processed ${processed}/${total} rows`);
    // Handle chunk of rows here
  },
  onComplete: (allRows) => {
    console.log('Processing complete!');
  },
  onError: (error) => {
    console.error('Error:', error);
  }
});

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

Parse CSV from a browser ReadableStream and return parsed data as JSON array Processes data in chunks for memory-efficient handling of large streams

Parameters:
Name Type Description
stream object

Browser ReadableStream containing CSV data

View Source src/browserApi.js, line 179

If stream is invalid

If streaming is not supported or parsing fails

Promise resolving to array of objects representing CSV rows

Promise.<Array.<object>>
Example
const csvToJson = require('convert-csv-to-json');
const response = await fetch('large-dataset.csv');
const stream = response.body;
const data = await csvToJson.browser.getJsonFromStreamAsync(stream);
console.log(data);

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

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