GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • GitHub
  • Generate
  • Parse
  • Transform
  • Stringify
  • How to contribute
  • GitHub
  • Issue Tracker
  • License
  • Homepage
  • Converter
  • API
  • Stream
  • Callback

This view

  • Original page
  • New address

GeezerVison is showing csv.js.org — CSV Parse - Sync API

Sync API

The sync API exposes a function, which expects as input a full dataset as text, and which returns the full result set as an array or an object.

To summarise, it is a regular direct synchronous call to a function: you pass CSV content and it returns records. Because of its simplicity, this is the recommended approach if you don't need scalability and if your dataset fit in memory.

Choose the sync API for simplicity, readability and convenience at the expense of not being scalable.

Import or require the csv-parse/sync module to use it. The exported function signature is const records = parse(data, [options]).

The synchronous example illustrates how to use the synchronous module. This example is available with the command node samples/api.sync.js.

import assert from "node:assert";
import { parse } from "csv-parse/sync";

const input = `
"key_1","key_2"
"value 1","value 2"
`;
const records = parse(input, {
  columns: true,
  skip_empty_lines: true,
});
assert.deepStrictEqual(records, [{ key_1: "value 1", key_2: "value 2" }]);
./packages/csv-parse/samples/api.sync.js

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.