CSV in JavaScript / es6 – Parse CSV with PapaParse

Fast and powerful CSV (delimited text) parser, that gracefully handles large files and malformed input! Parse CSV in JavaScript with no pain!

Parse CSV in JavaScript

Papa Parse is the fastest in-browser CSV (or delimited text) parser for JavaScript. It is reliable and correct according to RFC 4180, and it comes with features such as:

– Parse CSV files directly (local or over the network)
– Header row support
– Pause, resume, abort
– Fast mode (is really fast)
– Stream large files (even via HTTP)
– Reverse parsing (converts JSON to CSV)
– Auto-detect delimiter
– Worker threads to keep your web page reactive
– Can convert numbers and booleans to their types
– One of the only parsers that correctly handles line-breaks and quotations
– Easy to use

Papa Parse has no dependencies – not even jQuery.

PapaParse - csv in JavaScript!
PapaParse – csv in JavaScript!

Papa Parse can parse a Readable Stream instead of a File when used in Node.js environments (in addition to plain strings). In this mode, encoding must, if specified, be a Node-supported character encoding. The Papa.LocalChunkSize, Papa.RemoteChunkSize , download, withCredentials and worker config options are unavailable.

Papa Parse can also parse in a node streaming style which makes .pipe available. Simply pipe the Readable Stream to the stream returned from Papa.parse(Papa.NODE_STREAM_INPUT, options). The Papa.LocalChunkSize, Papa.RemoteChunkSize , download, withCredentials, worker, step, and complete config options are unavailable. To register a callback with the stream to process data, use the data event like so: stream.on(‘data’, callback) and to signal the end of stream, use the ‘end’ event like so: stream.on(‘end’, callback).

Setup

npm install papaparse

Sample

// Parse CSV string
var data = Papa.parse(csv);

// Convert back to CSV
var csv = Papa.unparse(data);

// Parse local CSV file
Papa.parse(file, {
  complete: function(results) {
    console.log("Finished:", results.data);
  }
});

// Stream big file in worker thread
Papa.parse(bigFile, {
  worker: true,
  step: function(results) {
    console.log("Row:", results.data);
  }
});

License: MIT

Homepage
https://www.papaparse.com

Docs

https://www.papaparse.com/docs

GitHub

https://github.com/mholt/PapaParse

scraperapi

See also

Excel in JavaScript / jQuery – jExcel

JavaScript JSON editor online

JSON data with colored syntax – pretty-print-json

jQuery JSON form builder – HTML forms from JSON Schema

jQuery convert JSON to grid plugin – Columns

JavaScript Excel tables library

jQuery data TreeTable plugin

Enjoy!