https://github.com/remko/json-array-streams
Streams for JSON array parsing/stringifying
https://github.com/remko/json-array-streams
Last synced: 11 months ago
JSON representation
Streams for JSON array parsing/stringifying
- Host: GitHub
- URL: https://github.com/remko/json-array-streams
- Owner: remko
- Created: 2015-09-01T21:11:48.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2020-11-07T15:41:38.000Z (over 5 years ago)
- Last Synced: 2025-07-04T08:23:57.689Z (12 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# [json-array-streams: Streams for JSON array parsing/stringifying](https://el-tramo.be/json-array-streams)
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.