JSON.stringify as pull-stream
npm install pull-stringifyJSON.stringify as pull stream
`` js
var pull = require('pull-stream')
var stringify = require('pull-stringify')
var toPull = require('stream-to-pull-stream')
pull(
pull.values([A, B, C]),
stringify(),
toPull(process.stdout)
)
`
` js`
pull(
pull.values([A, B, C]),
stringify.lines(),
toPull(process.stdout)
)
options is an object with the following optional keys:
- open: string to be prepended to first output stringprefix
- : string to be prepended to every non-first output stringsuffix
- : string to be appended to every output stringclose
- : string to be appended after stream is completeindent
- : passed as third argument to JSON.stringifystringify
- : custom function to use instead of JSON.stringify
stringify(options) returns a through pull-stream.
defaults options are for double newline delimited json. double newline delimiting means you can use indented json as the stream format, which is more human readable.
`js`
{
open: '',
prefix: '',
suffix: '\n\n',
close: '',
indent: 2,
stringify: JSON.stringify
}
for single newline delimited json use stringify.ldjson() or stringify.lines():
`js`
{
suffix: '\n',
indent: 0
}
you can pass a custom stringify as an argument.
`js
// compatible with JSON but supports buffers.
var JSONB = require('json-buffer')
// use defaults
stringify({ stringify: JSONB.stringify })
// or
stringify.lines(JSONB.stringify)
`
for a single json array use stringify.array()
`js``
{
open: '[',
separator: ',\n',
close: ']\n',
indent: 2
}
MIT