CHECKING STATUS
I AM LISTENING TO
|
  • ♩
  • ♪
  • ♫
  • ♬
  • ♩
  • ♪
  • ♫
  • ♬

Importing CSV files with HTML5 and Papa Parse!

LAST MODIFIED: 5. February 2025
5. February 2021
.SHARE

PAPA PARSE

Papa Parse is a powerful, in-browser CSV parser for the big boys and girls :)
If you do need easy CSV parsing and conversion back to CSV, take a look at it!

// 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);
	}
});

SIMPLE TESTDRIVE

 <input type="file" name="File Upload" id="txtFileUpload" accept=".csv" />
document.getElementById('txtFileUpload').addEventListener('change', upload, false);

 function upload(evt) {
  
	var data = null;
	var file = evt.target.files[0];
	var reader = new FileReader();
	reader.readAsText(file);
	reader.onload = function(event) {
		var csvData = event.target.result;
		
		 var data = Papa.parse(csvData, {header : true});
		
		console.log(data);
		
	};
	reader.onerror = function() {
		alert('Unable to read ' + file.fileName);
	};

}

ABOUT

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 these features:

  • Easy to use
  • Parse CSV files directly (local or over the network)
  • Fast mode
  • Stream large files (even via HTTP)
  • Reverse parsing (converts JSON to CSV)
  • Auto-detect delimiter
  • Worker threads to keep your web page reactive
  • Header row support
  • Pause, resume, abort
  • Can convert numbers and booleans to their types
  • Optional jQuery integration to get files from <input type="file"> elements
  • One of the only parsers that correctly handles line-breaks and quotations

USAGE

I am currently using it to quickly parse Adobe Audition CSV marker files and prepare them for storage for my podcast.

Name	Start	Duration	Time Format	Type	Description
Ankündigungen	0:20.432	0:00.000	decimal	Cue	
Stargate Table Read	1:12.811	0:00.000	decimal	Cue	
Dune Part One 2021	1:58.677	0:00.000	decimal	Cue	
Dust - Cosmo	2:20.925	0:00.000	decimal	Cue	
Nina - Beyond Memory	2:51.276	0:00.000	decimal	Cue	
Papa.unparse(tabData, {	
	delimiter: "\tab",
	header: true,
	newline: "\r\n",
	skipEmptyLines: true
})

Papa Parse @ GitHUB

Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

FAQ What is the best free open source way to back up IMAP email? For most people, mbsync (isync) pulls IMAP into a local Maildir reliably on Linux, macOS and Windows via WSL, and imap-backup does the same job with an easier cross-platform setup and no config-file syntax to learn. Pair whichever you choose with […]

Your keyboard and pointing device are the two tools you touch more than anything else on your desk — more than your monitor, more than your editor. A developer types for a living, and after enough years of it, the wrong keyboard and mouse stop being a minor annoyance and start being a wrist problem […]

If you’re a developer in Europe who works from home and runs a homelab, your chair and desk are the two pieces of hardware you touch more than any server, keyboard or monitor. You’ll spend thousands of hours in that seat, and a scary amount of expensive gear is going to live on that desk. […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs

I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.