streaming-json-stringify
Streaming JSON.stringify()
Last updated 11 years ago by jongleberry .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install streaming-json-stringify 
SYNC missed versions from official npm registry.

Streaming JSON.stringify()

NPM version Build status Test coverage Dependency Status License Downloads

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'.

Stringifier

By default, json-stringify-safe is used to convert objects into strings. This can be configured with options.stringifier.

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
stringify.opener = '['
stringify.seperator = ','
stringify.closer = ']'
stringify.stringifier = JSON.stringify

Current Tags

  • 3.1.0                                ...           latest (10 years ago)

10 Versions

  • 3.1.0                                ...           10 years ago
  • 3.0.0                                ...           10 years ago
  • 2.2.0                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           12 years ago
  • 0.2.2                                ...           13 years ago
  • 0.2.1                                ...           13 years ago
  • 0.2.0                                ...           13 years ago
Downloads
Today 0
This Week 0
This Month 9
Last Day 0
Last Week 9
Last Month 1
Dependencies (2)
Dev Dependencies (3)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |