🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

csv-stream-to-json

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csv-stream-to-json

Takes a CSV file stream and parse it line by line to JSON. It accepts two callbacks: 1. Called for each file line, 2. Called at the end of the file parsing and gets passed the whole json array

1.0.1
latest
Version published
Weekly downloads
57
21.28%
Maintainers
1
Weekly downloads
 
Created

CSV File Stream To JSON

Takes a CSV file stream and parse it line by line to JSON. It accepts two callbacks: 1. Called for each file line, 2. Called at the end of the file parsing and gets passed the whole json array.

How to install

    npm install csv-stream-to-json --save

API

 parse ([Stream] inStream, [Character] separator, [Bool] toArray, [Function] rowCb, [Function] done) : Void
  • inStream: CSV file Readable strem
  • separator: Separator Character
  • toArray: Wheater it should return the whole document as an objects array in the done callback
  • rowCb: Callback to be executed for every parsed row. it receives the resulting object.
  • done: Callback executed at the end of the document.

How to use it

  //Creating read stream from file uploaded to server
  var readable = req.file('avatar').read();

    csvToJson.parse(readable, ",", false, obj => {
       console.log(obj);
    }, arr => {
        console.log(arr);
    });

FAQs

Package last updated on 10 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts