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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.0
    0

Package Sidebar

Install

npm i json-around

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • psalaets