API Reference

PapaParse

Fast in-browser CSV parser for JavaScript with header mapping, workers, and streaming chunks.

Official Documentation ↗
CompatibilityThis documentation covers version v5. Check the official docs for the latest API surface.

Installation

npmnpm install papaparse
pnpmpnpm add papaparse

Methods

Fast in-browser CSV parser for JavaScript with header mapping, workers, and streaming chunks.

Overview

PapaParse is the practical CSV engine for browsers: string parsing is synchronous and simple, File parsing streams in chunks, and worker: true offloads the CPU work. header maps rows to keyed objects, and dynamic typing converts numeric-looking cells automatically when asked.

Results separate data from typed errors and metadata, so callers can enforce column contracts and row policies explicitly. unparse closes the loop with correctly quoted output, including custom delimiters for TSV.

Core Methods

The most frequently used entry points, with signatures and runnable examples:

  • Papa.parse — Parses a string synchronously or asynchronously; the config decides behavior and callbacks.
  • Papa.parse (File) — Reads browser File inputs, optionally on a web worker, without loading the whole file.
  • results structure — Parsed rows plus typed errors per row and metadata about the discovered format.
  • Papa.unparse — Serializes rows back to CSV with proper quoting of delimiters and newlines.

Usage Notes

  • Validate meta.fields against required columns before processing rows.
  • Use chunk plus worker for user-supplied files to keep the UI responsive.
  • Check results.errors and define a policy instead of ignoring malformed rows.

Common Pitfalls

  • Silently reading undefined on ragged rows hides upstream data quality problems.
  • dynamicTyping converts “01” to 1 and loses leading zeros such as postal codes.
  • complete fires even when errors exist, always inspect both.

FAQ

How do I handle very large files?
Pass a File with chunk and stream rows as they parse; worker: true moves parsing off the main thread. Neither loads the entire document into memory, so hundred-megabyte exports stay responsive.
Why are some rows missing fields?
Ragged rows produce entries in results.errors with a row index, such as TooFewFields or TooManyFields. Decide policy explicitly: reject the file, skip rows, or pad, rather than reading undefined silently.
Does PapaParse work in Node.js?
It runs in Node for string and stream parsing, but File and worker support is browser-oriented. For heavy server-side pipelines, prefer a streaming CSV library built for Node streams and keep PapaParse for browser imports.