Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/thlorenz/ndjson-aggregator

Aggregates ndjson output into one JSON object, keyed by a given property.
https://github.com/thlorenz/ndjson-aggregator

Last synced: 13 days ago
JSON representation

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

Awesome Lists containing this project

README

        

# ndjson-aggregator [![build status](https://secure.travis-ci.org/thlorenz/ndjson-aggregator.png)](http://travis-ci.org/thlorenz/ndjson-aggregator)

[![testling badge](https://ci.testling.com/thlorenz/ndjson-aggregator.png)](https://ci.testling.com/thlorenz/ndjson-aggregator)

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

```js
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*.

```sh
ndja < 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](https://github.com/thlorenz/docme)*

## License

MIT