Papa Parse

A powerful, in-browser CSV parser for big boys and girls

P

Now the fastest JavaScript CSV parser for the browser
The world's first multi-threaded CSV parser for the browser
Use Papa when performance, privacy, and correctness matter to you
Papa is easy to use:
var results = Papa.parse(csv);
Convert JSON to CSV:
var csv = Papa.unparse(json);
Companies trust Papa to help alleviate privacy concerns related to uploading files.
Malformed CSV is handled gracefully with a detailed error report.

Features

And Papa's blazing fast!
// Convert CSV to JSON var results = Papa.parse(csv); // Parse local CSV files $('input[type=file]').parse({ config: { complete: function(results) { console.log("Parse results:", results.data); } } }); // In a worker thread Papa.parse(fileOrString, { worker: true, complete: function(results) { console.log("Parse results:", results.data); } });
People Papa
If you love your Papa, let me know and we'll get your logo added to this page.
  Get Papa Parse on GitHub   Try the demo
Delimeter auto-detect

"I don't know the delimiter..."

That's okay. Papa will scan the first few rows of input to find the right delimiter for you. You can also set the delimiting character manually. Either way, the delimiter used is returned with every result set.

var results = Papa.parse(csvString); console.log(results); /* { data: [ ... ] errors: [ ... ] meta: { delimiter: "\t", ... } } */

Parse local files

"Great, but I have a file to parse."

Just give Papa a File instead of a string. And a callback.

Papa.parse(file, { complete: function(results) { console.log(results); } });

Parse remote files

"No, you don't understand. The file isn't local."

Well then just give Papa the URL and—of course—a callback.

Papa.parse("http://example.com/foo.csv", { download: true, complete: function(results) { console.log("Remote file parsed!", results); } });

Streaming

"Did I mention the file is huge?"

That's what streaming is for. Specify a step callback to receive the results row-by-row. This way, you won't load the whole file into memory and crash the browser.

Papa.parse("http://example.com/bigfoo.csv", { download: true, step: function(row) { console.log("Row:", row.data); }, complete: function() { console.log("All done!"); } });

Multi-threading

"Lovely. Now my web page locked up."

Oh. Yeah, that happens when a long-running script is executing in the same thread. Use a Worker thread by specifying worker: true. It may take slightly longer, but your page will stay reactive.

Papa.parse(bigFile, { worker: true, step: function(row) { console.log("Row:", row.data); }, complete: function() { console.log("All done!"); } });

"Great! Now I want data keyed by field name."

You can tell Papa that there is a header row.

// Key data by field name instead of index/position var results = Papa.parse(csv, { header: true });

Type Conversion

"Hey, these numbers are all parsed as strings."

Everything is parsed as strings. If you need the convenience, you can have numeric and boolean data automatically converted to number and boolean types.

// All parsed data is normally returned as a string. // Dynamic typing converts numbers to numbers // and booleans to booleans. var results = Papa.parse(csv, { dynamicTyping: true });

Comments

"I forgot to mention: my CSV files have comments in them."

Okay, first off: that's really weird. But you can skip those lines... just specify the comment character.

// Mostly found in academia, some CSV files // may have commented lines in them var results = Papa.parse(csv, { comments: "#" });

Error handling

"I'm getting tired, are we done—aw, shoot. Errors."

Yeah, almost done. Fortunately, Papa handles errors pretty well. The CSV standard is somewhat loose ambiguous, so Papa tries to consider the edge cases. For example, mismatched fields aren't always the end of the world.

// Example error: { type: "FieldMismatch", code: "TooManyFields", message: "Expected 3 fields, but parsed 4", row: 1 }

jQuery Plugin

"Can I use Papa with jQuery?"

Sure, but it's not required. You can use jQuery to select file input elements and then parse their files. Papa exposes its file parsing API as a jQuery plugin only when jQuery is defined. Papa Parse has no dependencies.

$("input[type=file]").parse({ config: { complete: function(results, file) { console.log("File done:", file, results); } }, complete: function() { console.log("All files done!"); } });

JSON to CSV

"Last thing: what about converting JSON to CSV?"

Call unparse() instead of parse(), passing in your array of arrays or array of objects. Papa will figure it out.

// Output is a properly-formatted CSV string. // See the docs for more configurability. var csv = Papa.unparse(yourData);

Who's your Papa?

Mini Papa for production use
Fat Papa for debug and development