Anonymous View
Skip to content

remko/json-array-streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This package provides streams for parsing and stringifying a stream of objects to a JSON array. This is useful when you have huge lists of generated data from a stream that you can't (or don't want to) entirely keep in memory, and instead want to directly stream this to/from storage.

Installation

npm install json-array-streams --save

Usage

var through = require("through2");
var fs = require("fs");
var jsonArrayStreams = require("json-array-streams");

// Write a stream of objects to a JSON file
createSomeObjectStream()
  .pipe(jsonArrayStreams.stringify())
  .pipe(fs.createWriteStream("data.json"));

// Read a stream of objects from a JSON file
fs.createReadStream("data.json")
  .pipe(jsonArrayStreams.parse())
  .pipe(through.obj(function (object, enc, cb) {
    console.log("Got object", object);
    cb();
  }));

API

jsonArrayStreams.parse()

Create a parsing stream.

jsonArrayStreams.stringify([replacer, [space]])

Create a stringifying stream.

replacer, space are optional parameters that are passed to JSON.stringify, to support pretty-printing the output.

About

Streams for JSON array parsing/stringifying

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors