https://github.com/fent/node-jstream
Continuously reads in JSON and outputs Javascript objects.
https://github.com/fent/node-jstream
json-parser node stream
Last synced: 8 months ago
JSON representation
Continuously reads in JSON and outputs Javascript objects.
- Host: GitHub
- URL: https://github.com/fent/node-jstream
- Owner: fent
- License: mit
- Created: 2012-03-19T12:50:40.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2023-08-31T21:00:36.000Z (almost 3 years ago)
- Last Synced: 2025-10-22T00:52:26.657Z (8 months ago)
- Topics: json-parser, node, stream
- Language: JavaScript
- Homepage:
- Size: 88.9 KB
- Stars: 19
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-jstream
Continuously reads in JSON and outputs Javascript objects. Meant to be used with keep-alive connections that send back JSON on updates.
[](http://travis-ci.org/fent/node-jstream)
[](https://david-dm.org/fent/node-jstream)
[](https://codecov.io/gh/fent/node-jstream)
# Usage
```js
const JStream = require('jstream');
const request = require('request');
request('http://api.myhost.com/updates.json')
.pipe(new JStream()).on('data', (obj) => {
console.log('new js object');
console.log(obj);
});
```
# API
### new JStream([path])
Creates an instance of JStream. Inherits from `Stream`. Can be written to and emits `data` events with Javascript objects.
`path` can be an array of property names, `RegExp`'s, booleans, and/or functions. Objects that match will be emitted in `data` events. Passing no `path` means emitting whole Javascript objects as they come in. For example, given the `path` `['results', true, 'id']` and the following JSON gets written into JStream
```js
{ "results": [
{"seq":99230
,"id":"newsemitter"
,"changes":[{"rev":"5-aca7782ab6beeaef30c36b888f817d2e"}]}
, {"seq":99235
,"id":"chain-tiny"
,"changes":[{"rev":"19-82224279a743d2744f10d52697cdaea9"}]}
, {"seq":99238
,"id":"Hanzi"
,"changes":[{"rev":"4-5ed20f975bd563ae5d1c8c1d574fe24c"}],"deleted":true}
] }
```
JStream will emit `newsemitter`, `chain-tiny`, and `Hanzi` in its `data` event.
### JStream.MAX_BUFFER_LENGTH
Defaults to 64 * 1024.
# Install
npm install jstream
# Tests
Tests are written with [mocha](https://mochajs.org)
```bash
npm test
```