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

VersionDownloads (Last 7 Days)Tag
0.0.30latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i pull-json-stringify

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

3.8 kB

Total Files

4

Last publish

Collaborators

  • thomas-jensen