Menu

This is documentation for the next version of K6. For the latest stable release, go to the latest version.

Open source

Options

The Options object describes the configuration available for the operation of parsing CSV files using the csv.parse function and the csv.Parser class.

Properties

PropertyTypeDescription
delimiterstringThe character used to separate fields in the CSV file. Default is ','.
skipFirstLinebooleanWhether to skip the first line of the CSV file. Default is false.
fromLine(optional) numberThe line number from which to start reading the CSV file. Default is 0.
toLine(optional) numberThe line number at which to stop reading the CSV file. If the option is not set, then read until the end.

Example

JavaScript
import { open } from 'k6/experimental/fs';
import csv from 'k6/experimental/csv';

const file = await open('data.csv');
const parser = new csv.Parser(file, {
  delimiter: ',',
  skipFirstLine: true,
  fromLine: 2,
  toLine: 8,
});

export default async function () {
  // The `next` method attempts to read the next row from the CSV file.
  //
  // It returns an iterator-like object with a `done` property that indicates whether
  // there are more rows to read, and a `value` property that contains the row fields
  // as an array.
  const { done, value } = await parser.next();
  if (done) {
    throw new Error('No more rows to read');
  }

  // We expect the `value` property to be an array of strings, where each string is a field
  // from the CSV record.
  console.log(done, value);
}