npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

csvtojsonlines

v1.0.0

Published

Parse csv data into jsonl (one JSON object per line)

Downloads

10

Readme

csvtojsonl

A simple command-line utility that transforms a CSV file into JSON documents - one document per line.

The default CSV delimiter is the tab character and it is expected that the first line of the file contains column headings which will become the JSON attribute names.

Installation

npm install -g csvtojsonlines

Usage

Pipe a CSV/TSV file to csvtojsonlines (or its alias csvtojsonl) e.g.

> cat guitars.tsv | csvtojsonlines
{"product_id":"26","brand":"Gibson","type":"Electric","range":"Flying V","model":"Flying V 120","country":"USA","year":"2014","colour":"White","price":"1999.00","description":"The Flying V is the original rebel-rousing rocker, way ahead of its time in the late ’50s and still a major style statement today. Following in the footsteps of this iconic guitar, the Limited Run Flying V 120 is the perfect candidate to join in Gibson USA’s 120th Anniversary celebrations. Combining time-tested tonewoods, versatile pickups, and unparalleled Gibson USA craftsmanship at an unbeatable price, the Flying V 120 launches your music into the stratosphere, while making the perfect ticket to the party for collector and player alike.","url":"http://www2.gibson.com/Products/Electric-Guitars/Flying-V/Gibson-USA/Flying-V-120.aspx","image":"http://images.gibson.com/Products/Electric-Guitars/Designer/Gibson-USA/Flying-V-120/Gallery-Images/DV120CWCH1-Finish-Shot.jpg","sold":"FALSE"}

or redirect the output to a file

cat transactions.csv | csvtojsonlines --delimiter ',' > output.jsonl

Parameters

  • --delimiter/-d - the CSV file delimiter to expect (default :\t)
  • --help/-h - show help

Using programmatically

The csvtojsonlines function expects an object with the following items:

  • rs the Node.js readstream where the input will come from.
  • ws the Node.js writestream where the text output will go to.
  • delimiter the CSV delimiter e.g. ','
const fs = require('fs')
const csvtojsonlines = require('csvtojsonlines')

const main = async () => {
  const opts = {
    rs: fs.createReadStream('./hp1.csv'),
    ws: process.stdout,
    delimiter: ','
  }
  await csvtojsonlines(opts)
}
main()