0.1.2 • Published 9 years ago

ndjson-aggregator v0.1.2

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

ndjson-aggregator build status

testling badge

Aggregates ndjson output into one JSON object, keyed by a given property.

var aggregate = require('ndjson-aggregator')

var lines = [
    '{"name":"buffers/buffer-creation","config":{"type":"fast","len":10,"n":1024},"time":"5400.10125"}'
  , '{"name":"buffers/buffer-creation","config":{"type":"fast","len":1024,"n":1024},"time":"2097.43265"}'
  , '{"name":"buffers/buffer-deletion","config":{"type":"fast","len":10,"n":1024},"time":"5400.10125"}'
  , '{"name":"buffers/buffer-deletion","config":{"type":"fast","len":1024,"n":1024},"time":"2097.43265"}'
  , '{"config":{"type":"fast","len":10,"n":1024},"time":"5400.10125"}'
  , '{"config":{"type":"fast","len":1024,"n":1024},"time":"2097.43265"}'
]

var res = aggregate(lines, 'name')
console.log(res)
{ 'buffers/buffer-creation':
   [ { name: 'buffers/buffer-creation',
       config: { type: 'fast', len: 10, n: 1024 },
       time: '5400.10125' },
     { name: 'buffers/buffer-creation',
       config: { type: 'fast', len: 1024, n: 1024 },
       time: '2097.43265' } ],
  'buffers/buffer-deletion':
   [ { name: 'buffers/buffer-deletion',
       config: { type: 'fast', len: 10, n: 1024 },
       time: '5400.10125' },
     { name: 'buffers/buffer-deletion',
       config: { type: 'fast', len: 1024, n: 1024 },
       time: '2097.43265' } ],
  'ENOEXIST name':
   [ { config: { type: 'fast', len: 10, n: 1024 },
       time: '5400.10125' },
     { config: { type: 'fast', len: 1024, n: 1024 },
       time: '2097.43265' } ] }

Installation

npm install ndjson-aggregator

CLI

A cli tool name ndja will be in your path if you install this package globally.

It takes a stream of ndjson data from stdin and outputs aggregated JSON to stdout.

ndja <property> < in-ndjson.data > out.json 

## Example

ndja name < examples/ndjson.data > out.json 

API

generated with docme

License

MIT

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago