# streaming-json-stringify

> Streaming JSON.stringify()

Latest version **3.1.0** (published 2015-10-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install streaming-json-stringify
pnpm add streaming-json-stringify
yarn add streaming-json-stringify
bun add streaming-json-stringify
```

## Health

**Score 33/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2015-10-29 |
| First published | 2013-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/streaming-json-stringify) |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 60 |
| Author | Jonathan Ong |
| Maintainers | jongleberry, dougwilson |
| Keywords | stream, json, stringify |

## Links

- npm: https://www.npmjs.com/package/streaming-json-stringify
- Repository: https://github.com/stream-utils/streaming-json-stringify
- Homepage: https://github.com/stream-utils/streaming-json-stringify#readme
- Issues: https://github.com/stream-utils/streaming-json-stringify/issues
- npm.io page: https://npm.io/package/streaming-json-stringify

## Dependencies (2)

- [readable-stream](https://npm.io/package/readable-stream.md) 2
- [json-stringify-safe](https://npm.io/package/json-stringify-safe.md) 5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 3.1.0 (latest) — 2015-10-29
- 3.0.0 — 2015-10-23
- 2.2.0 — 2015-07-15
- 2.1.0 — 2015-02-09
- 2.0.0 — 2014-12-26
- 1.0.1 — 2014-12-07
- 1.0.0 — 2013-11-30
- 0.2.2 — 2013-10-10
- 0.2.1 — 2013-09-27
- 0.2.0 — 2013-09-20

## README

# Streaming JSON.stringify()

[![NPM version][npm-image]][npm-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Dependency Status][david-image]][david-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

Similar to [JSONStream.stringify()](https://github.com/dominictarr/JSONStream#jsonstreamstringifyopen-sep-close) 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.

```js
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

```json
[
{"_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](https://www.npmjs.com/package/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:

```js
var stringify = Stringify()
stringify.replacer = function () {}
stringify.space = 2
stringify.opener = '['
stringify.seperator = ','
stringify.closer = ']'
stringify.stringifier = JSON.stringify
```

[gitter-image]: https://badges.gitter.im/stream-utils/streaming-json-stringify.png
[gitter-url]: https://gitter.im/stream-utils/streaming-json-stringify
[npm-image]: https://img.shields.io/npm/v/streaming-json-stringify.svg?style=flat-square
[npm-url]: https://npmjs.org/package/streaming-json-stringify
[github-tag]: http://img.shields.io/github/tag/stream-utils/streaming-json-stringify.svg?style=flat-square
[github-url]: https://github.com/stream-utils/streaming-json-stringify/tags
[travis-image]: https://img.shields.io/travis/stream-utils/streaming-json-stringify.svg?style=flat-square
[travis-url]: https://travis-ci.org/stream-utils/streaming-json-stringify
[coveralls-image]: https://img.shields.io/coveralls/stream-utils/streaming-json-stringify.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/stream-utils/streaming-json-stringify
[david-image]: http://img.shields.io/david/stream-utils/streaming-json-stringify.svg?style=flat-square
[david-url]: https://david-dm.org/stream-utils/streaming-json-stringify
[license-image]: http://img.shields.io/npm/l/streaming-json-stringify.svg?style=flat-square
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/streaming-json-stringify.svg?style=flat-square
[downloads-url]: https://npmjs.org/package/streaming-json-stringify

---
_Source: https://npm.io/package/streaming-json-stringify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
