pull-json-stringify

0.0.3 • Public • Published

JSON stringify for pull-streams

JSON serialize a pull-stream.

const pull = require('pull-stream');
const stringify = require('pull-json-stringify');

const data = [
	{ name: 'LEGO' },
	{ name: 'IKEA' },
];

pull(
	pull.values(data),
	stringify(),
	pull.concat(( err, json ) => console.log(json))
	/*
	{"name":"LEGO"}
	{"name":"IKEA"}
	*/
);

pull(
	pull.values(data),
	stringify({
		open: '[\n',
		close: '\n]',
		separator: ',\n',
	}),
	pull.concat(( err, json ) => console.log(json))
	/*
	[
	{"name":"LEGO"},
	{"name":"IKEA"}
	]
	*/
);

The ndjson format is the default.

The second example produces valid JSON.

Both formats are parsable using pull-json-parse, the second example's format being useful for having JSON compatibility while enjoying simple newline based parsing.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.3
    9
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.3
    9
  • 0.0.2
    1
  • 0.0.1
    1

Package Sidebar

Install

npm i pull-json-stringify

Weekly Downloads

11

Version

0.0.3

License

MIT

Unpacked Size

3.8 kB

Total Files

4

Last publish

Collaborators

  • thomas-jensen