开发者社区> 镜像站> NPM> ndjson-aggregator
ndjson-aggregator
Aggregates ndjson output into one JSON object, keyed by a given property.
Last updated 6 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ndjson-aggregator 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.1.2                                ...           latest (6 years ago)

3 Versions

  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (0)
None
Dev Dependencies (3)
Dependents (2)