Skip to content

srcagency/pull-json-stringify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

JSON.stringify for pull-streams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published