Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/thlorenz/ndjson-aggregator
- Owner: thlorenz
- License: mit
- Created: 2015-05-12T14:55:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-05-12T16:03:15.000Z (over 9 years ago)
- Last Synced: 2024-12-10T08:27:11.136Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 141 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
Returns:
ndjson aggregated into one JavaScript Object
Type
Object*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT