0.0.3 • Published 5 years ago

pull-json-stringify v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

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.