csv-stream-to-json

1.0.1 • Public • Published

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);
    });

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i csv-stream-to-json

      Weekly Downloads

      8

      Version

      1.0.1

      License

      ISC

      Last publish

      Collaborators

      • puricamaykol