Put a JSON string around an object stream.
Given this code
var through = require('through2');
var jsonAround = require('json-around');
var source = through.obj();
source
.pipe(jsonAround('animals', {
location: 'farm'
}))
.pipe(process.stdout);
source.write({name: 'horse'});
source.write({name: 'dog'});
source.write({name: 'cow'});
source.end();
stdout will (roughly) get
{
"location": "farm",
"animals": [
{"name":"horse"},
{"name":"dog"},
{"name":"cow"}
]
}
and it would have been streamed in chunks like
{"location":"farm","animals":[
{"name":"horse"},
{"name":"dog"},
{"name":"cow"}]}
String to use for the array's key in resulting JSON.
Object that will be converted to JSON and have array added to it.
Objects piped in will become elements of the array.
Output is chunks of json.
npm install json-around
MIT