
Converting CSV to JSON in Node With a Few Lines of Code
Convert a CSV to JSON or NDJSON in Node with csv-parse, keep ZIP codes as text, and stream 2,000,000 rows at 120 MB instead of 1.6 GB.
The format everyone exports and nobody specifies. Delimiters, quoting, encodings and loading it into a database intact.

Convert a CSV to JSON or NDJSON in Node with csv-parse, keep ZIP codes as text, and stream 2,000,000 rows at 120 MB instead of 1.6 GB.

line.split(',') breaks on quoted commas, quotes, line breaks and CRLF. See the failures, why the regex fix is slow, and a 30 line parser that works.

Build a CSV string, wrap it in a Blob and trigger a download with an object URL. Covers escaping, the Excel BOM, formula guards and how 1,000,000 rows behave.

Parse an uploaded CSV in the browser with Papa Parse: typing traps, error objects, encodings, and chunks and workers measured on 500,000 rows.

The csv-parse options that matter on big files in Node: columns, cast, on_record, relax_quotes and max_record_size, timed on 2,000,000 rows.

Read a large CSV in Node with fs.createReadStream and csv-parse, filter with pipeline, stop early, and handle errors, BOMs and Windows-1252 files.

A tested guide to CSV in JavaScript: csv-parse, Papa Parse and a hand-written parser timed on 2,000,000 rows, plus streams, types, uploads and downloads.

Split a CSV into one file per column value with awk, qsv, Miller or DuckDB, keep the header in every file, check the counts and avoid unsafe file names.

Remove duplicate CSV rows with sort -u, awk, qsv and Miller. See what each does to the header and the order, which row it keeps, and why awk drops a good row.

Sort a CSV by column from the shell without losing the header or reading text as numbers. Compare sort, qsv, Miller, csvsort and DuckDB on 2,000,000 rows.

Count records and distinct values in a CSV from the shell with wc, sort, uniq, qsv and Miller, and see why wc -l and messy spellings give wrong counts.

qsv counts, profiles, searches, slices and sorts CSV files in fractions of a second. See count, stats, frequency, slice and index run on 2,000,000 rows.
We send one email when a new article is published. No spam.