Fast and powerful CSV parser for the browser that supports web workers and streaming large files. Converts CSV to JSON and JSON to CSV.
PapaParse is a high-performance CSV parsing library designed to handle the complexities of real-world delimited data that naive JavaScript string methods cannot. Unlike String.split(','), it correctly processes quoted fields containing commas, handles line breaks within cells, manages inconsistent column counts, and provides detailed error reporting for malformed data. With over 6 million weekly downloads, it has become the de facto standard for client-side CSV processing.
The library shines in browser environments where large file parsing traditionally blocks the UI thread. By supporting web workers and streaming APIs, PapaParse can process gigabyte-sized files without crashing the browser or freezing user interactions. Its streaming mode parses files row-by-row or in configurable chunks, enabling real-time data processing without loading entire datasets into memory. This makes it viable for applications that previously required server-side processing.
PapaParse offers bidirectional conversion between CSV and JSON formats with extensive configuration options. Features include automatic delimiter detection, dynamic type conversion (strings to numbers/booleans), customizable quote/escape characters, header row parsing into object keys, and transformers for data manipulation during parsing. The library works seamlessly in both browser and Node.js environments with zero dependencies, maintaining consistent behavior across platforms while providing platform-specific optimizations like Readable Stream support in Node.js.
Typical users include data visualization developers processing user-uploaded files, analytics dashboard builders importing CSV reports, applications using Google Sheets as lightweight databases, and any web application requiring robust client-side data import functionality. The library's MIT license and standalone nature make it suitable for commercial and open-source projects alike.
import Papa from 'papaparse';
// Parse CSV file with streaming for large datasets
const fileInput = document.getElementById('csvFile');
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
let rowCount = 0;
Papa.parse(file, {
header: true,
dynamicTyping: true,
worker: true,
step: (result) => {
// Process each row as it's parsed
if (result.errors.length === 0) {
console.log('Row', ++rowCount, result.data);
// Example: { name: "John", age: 30, active: true }
} else {
console.error('Parse error:', result.errors);
}
},
complete: () => {
console.log(`Finished parsing ${rowCount} rows`);
},
error: (error) => {
console.error('File error:', error);
}
});
});
// Convert JSON back to CSV for download
const users = [
{ name: 'Alice', email: 'alice@example.com', role: 'admin' },
{ name: 'Bob', email: 'bob@example.com', role: 'user' }
];
const csv = Papa.unparse(users, {
quotes: true,
header: true
});
const blob = new Blob([csv], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = 'users.csv';
link.click();
// Node.js: Parse CSV string with custom configuration
const csvString = 'name,score\n"Smith, John",95\n"Doe, Jane",87';
const result = Papa.parse(csvString, {
header: true,
skipEmptyLines: true,
transformHeader: (header) => header.trim().toLowerCase(),
transform: (value) => value.trim()
});
console.log(result.data);
// [{ name: 'Smith, John', score: '95' }, { name: 'Doe, Jane', score: '87' }]User file upload processing: Web applications that accept CSV file uploads (customer lists, inventory data, transaction records) can parse files entirely client-side, reducing server load and improving privacy by never transmitting raw data. The streaming API prevents browser crashes on large files while web workers keep the UI responsive during parsing.
Real-time data dashboards: Analytics platforms can stream CSV data from remote endpoints using HTTP range requests, processing rows incrementally as they arrive. The step callback enables progressive rendering of charts and tables without waiting for complete file downloads, improving perceived performance.
Google Sheets as database: Applications can fetch published Google Sheets as CSV via public URLs and parse them into structured JSON for use as lightweight content management systems. PapaParse handles the formatting quirks and special characters that Google Sheets exports.
Data validation and cleaning: Import tools can leverage PapaParse's error handling to detect malformed CSV files, report specific issues (field mismatches, unexpected quotes), and transform data during parsing with custom functions. The preview option allows sampling large files before full processing.
Export functionality: Applications with data tables or reports can convert JSON datasets back to CSV format for user downloads. The unparse function handles proper escaping, quoting of special characters, and custom delimiters for Excel compatibility or specific regional formats.
npm install papaparsepnpm add papaparsebun add papaparse