Socket
Book a DemoInstallSign in
Socket

streaming-json-stringify

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streaming-json-stringify

Streaming JSON.stringify()

Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
227K
4.42%
Maintainers
2
Weekly downloads
 
Created
Source

Streaming JSON.stringify()

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Similar to JSONStream.stringify() except it is, by default, a binary stream, and it is a streams2 implementation.

Example

The main use case for this is to stream a database query to a web client. This is meant to be used only with arrays, not objects.

var Stringify = require('streaming-json-stringify')

app.get('/things', function (req, res, next) {
  res.setHeader('Content-Type', 'application/json; charset=utf-8')

  db.things.find()
  .stream()
  .pipe(Stringify())
  .pipe(res)
})

will yield something like

[
{"_id":"123412341234123412341234"}
,
{"_id":"123412341234123412341234"}
]

Separators

  • The stream always starts with '[\n'.
  • Documents are separated by '\n,\n'.
  • The stream is terminated with '\n]\n'.

API

Stringify([options])

Returns a Transform stream. The options are passed to the Transform constructor.

JSON.stringify options

You can override these:

var stringify = Stringify()
stringify.replacer = function () {}
stringify.space = 2

Keywords

stream

FAQs

Package last updated on 07 Dec 2014

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