ndjson-aggregator

0.1.2 • Public • Published

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

aggregate(lines, prop) → {Object}

Aggregates lines of new line delimited JSON into one JavaScript object keyed by a property if it is supplied.

If the key property is not supplied all ndjson lines will just be aggregated into one Array.

Parameters:
Name Type Argument Description
lines Array.<String>

ndjson lines (each line must be parseable JSON)

prop String <optional>

the property to key the aggregated JSON by

Source:
Returns:

ndjson aggregated into one JavaScript Object

Type
Object

generated with docme

License

MIT

Package Sidebar

Install

npm i ndjson-aggregator

Weekly Downloads

2

Version

0.1.2

License

MIT

Last publish

Collaborators

  • thlorenz