csv2json

Stream CSV to JSON

npm install csv2json
2 downloads in the last day
10 downloads in the last week
63 downloads in the last month

csv2json = CSV to JSON Stream Parser

Stream csv data and convert to json data

Usage

var csv2json = require('csv2json'),
  columns = ['foo','bar','baz'];

process.openStdin().pipe(csv2json(columns).pipe(process.stdout));
csv2json = require 'csv2json'
columns = ['foo','bar','baz']

process.openStdin().pipe csv2json(columns).pipe(process.stdout)

API

var csv2json = require('csv2json')


parameters

  • columns

Array of column names for each row that will be set as the json keys

  • columnSeparator (default ',')

The column separator for your csv file

  • rowSeparator (default '\n')

The row separator for you csv file

var parseRow = require('csv2json').parseRow;


  • columns

Array of column names for each row that will be set as the json keys

  • columnSeparator (default ',')

The column separator for your csv file

example

example.js

var es = require('event-stream'),
    parseRow = require('csv2json').parseRow;

es.pipe(
  es.openStdin(),
  es.split(),
  parseRow(['foo','bar','baz']),
  es.join(','),
  process.stdout
);
echo "'baz','bar','foo'" | node example.js

License

MIT

Contribute

pull requests are welcome

Thanks

npm loves you