npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

json-around

1.0.0 • Public • Published

json-around

Put a JSON string around an object stream.

Example

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"}]}

API

jsonAround(arrayPropertyName, wrapperObject)

arrayPropertyName

String to use for the array's key in resulting JSON.

wrapperObject

Object that will be converted to JSON and have array added to it.

returns a through stream

Objects piped in will become elements of the array.

Output is chunks of json.

Install

npm install json-around

License

MIT

install

npm i json-around

Downloadsweekly downloads

1

version

1.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability