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 🙏

© 2026 – Pkg Stats / Ryan Hefner

json2csv-stream-plus

v0.1.3

Published

Transform stream data from json to csv

Readme

json2csv-stream-plus

Forked from this repo json2csv-stream. ALL credit should go to it's original author. This version was created to fill a need with a current project and has been shared in case it is useful for anyone else out there.

The original repo is deprecated and is no longer being maintained. This repo can be maintained if there is wider interest in using it.

This module transforms json to csv data using streams for transforming the incoming data. The module is built with the new streaming API from Node.js v0.10.0 but maintains backwards compatibility to earlier Node.js versions.

Listen for header and line events or pipe the data directly to a readable stream.

Install with

$ npm install json2csv-stream-plus

Transform and pipe data to readable stream

Input - data.json

[
  {"car": "Audi","price": 40000,"color": "blue"},
  {"car": "BMW","price": 35000,"color": "black"},
  {"car": "Mercedes","price": 80000,"color": "red"},
  {"car": "Porsche","price": 60000,"color": "green"}
]

Transformation process

var fs = require('fs');
var MyStream = require('json2csv-stream-plus');

// create the transform stream
var parser = new MyStream();

// create the read and write streams
var reader = fs.createReadStream('data.json');
var writer = fs.createWriteStream('out.csv');

reader.pipe(parser).pipe(writer);

Output - out.csv

car,price,color
Audi,40000,blue
BMW,35000,black
Mercedes,80000,red
Porsche,60000,green

Use header and line events

If you want to further manipulate your data listen on the custom events.

parser.on('header', function(data) {
  console.log(' ++ yeah header found ++');
  console.log(data);
});

parser.on('line', function(data) {
  console.log(' ++ yeah line found ++');
  console.log(data);
});

Usage

var MyStream = require('json2csv-stream-plus');

// create the parsing stream with default options
var parser = new MyStream();

// create the stream with custom options. All options are optional.
var parser = new MyStream(options);

The following options are supported

  • del: Delimiter for csv values. Default is ,.
  • keys: Specify the keys you'd like to output. In the default setting all keys are exported.
  • eol: End-of-line marker. Default is the one used by the operating system.
  • showHeader: If you don't want the header line in your csv set to false. Default is true.
  • escapeValues: If true will wrap each value with ". Default is false.

Use optional custom delimiter

The default delimiter is , (comma). If you want to have tab-seperated values \t or semilocon-seperated values ; you can specify an optional delimiter using the del property.

var parser = new MyStream({
  del: ';'
});

Use optional specific keys

You can specify which key-value pairs you'd like to include in your .csv file. Use the keys property.

var parser = new MyStream({
  keys: ['car', 'color']
});

Use optional end-of-line markers

The default end-of-line marker is os.eol. That means \n on unix systems and \r\n on windows machines. You can specify your own end-of-line markers with the eol property in the options.

var parser = new MyStream({
  eol: '\r\n'
});

Use without writing the header line

If you want your csv data without the header line set showHeader to false;

var parser = new MyStream({
  showHeader: false
});

Use with wrapping individual values in double-quotes

If your values contain the same character as your delimiter set the escapeValues option to true. Doing so will wrap each value in double-quotes.

var parser = new MyStream({
  escapeValues: true
});

Benchmark

Go into the /benchmark folder and run

$ node benchmark.js

Results:

Executed benchmark against node module: "json2csv-stream-plus"
Count (34), Cycles (3), Elapsed (6.179 sec), Hz (563.3422353498144 ops/sec)

Executed benchmark against node module: "json2csv"
Count (38), Cycles (5), Elapsed (6.241 sec), Hz (652.5024167610189 ops/sec)

Module: "json2csv" wins.

Test

You need to have grunt-cli installed.

$ grunt test

or

$ npm test

Original License

Copyright (C) 2012 [Mirco Zeiss](mailto: [email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.