Skip to content

A utility for stringifying large JSON object arrays using node streams.

License

Notifications You must be signed in to change notification settings

bienzaaron/array-stringify-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

array-stringify-stream

npm version

array-stringify-stream is a utility which stringifies JavaScript arrays into JSON using node streams. This is helpful for writing very large JSON arrays, where the entire array may not fit in application memory.

Usage:

const someArray = [
  "string",
  0,
  ["nested", "array", { with: "object" }],
  { key: "value" },
];

const stringified = await pipeline(
  Readable.from(someArray),
  stringify(),
  fs.createWriteStream('./file.json')
);
// file.json contains '["string",0,["nested","array",{"with":"object"}],{"key":"value"}]'

Writing as ndjson:

const stringified = await pipeline(
  Readable.from(someArray),
  stringify("", "", "\n"),
  fs.createWriteStream('./file.json')
);
// file.json contains '"string"\n0\n["nested","array",{"with":"object"}]\n{"key":"value"}'

Using a custom stringifier function:

const stringified = await pipeline(
  Readable.from(someArray),
  stringify("[", "]", ",", (obj) => 'foo'),
  fs.createWriteStream('./file.json')
);
// file.json contains ["foo", "foo", "foo", "foo"]

About

A utility for stringifying large JSON object arrays using node streams.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published