Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felixge/newline-json
New line separated JSON streaming parser and stringifier
https://github.com/felixge/newline-json
Last synced: about 2 months ago
JSON representation
New line separated JSON streaming parser and stringifier
- Host: GitHub
- URL: https://github.com/felixge/newline-json
- Owner: felixge
- Created: 2014-04-04T12:29:53.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-04T12:48:32.000Z (over 10 years ago)
- Last Synced: 2024-10-11T15:19:21.115Z (2 months ago)
- Language: JavaScript
- Size: 116 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# newline-json
Just like [JSONStream](https://github.com/dominictarr/JSONStream),
but instead of streaming valid JSON arrays, it streams new-line separated
JSON objects.## Example
If you have a readable stream like
```js
var n = 100;
var nlj = new Readable();
nlj._read = function _read () {
if (n--)
nlj.push('{"this":"is","js":"on"}\n'); // new-line separated JSON!
else
nlj.push(null);
}
return nlj;
```you can pipe it to the parser
```js
var Parser = require('newline-json').Parser;
var parser = new Parser();
nlj.pipe(parser);
```what comes out of the parser will be the the objects you piped to it, parsed.
You can pipe those again to the stringifier:```js
var Stringifier = require('newline-json').Stringifier;
var stringifier = new Stringifier();
parser.pipe(stringifier);
```And if you have nothing better to do today, be sure to try
```js
parser.pipe(stringifier);
stringifier.pipe(parser);
```## Why ?
Couldn't find one on npm that used the
[`Transform`](http://nodejs.org/api/stream.html#stream_class_stream_transform_1),
and IMO if you don't need to parse complex object paths, then you'd be better off
using a new-line separated JSON. Also, it's probably much easier to write parsers
like this in other languages and environments, which is good if your stack is
not 100% node.js.