collect-json
Version:
Returns a stream which becomes readable with a single value once all (valid) JSON is received.
45 lines (33 loc) • 2.03 kB
Markdown
[](https://www.npmjs.org/package/collect-json)
[](https://www.npmjs.org/package/collect-json)
[](https://github.com/75lb/collect-json/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/collect-json/network/dependents?dependent_type=PACKAGE)
[](https://travis-ci.org/75lb/collect-json)
[](https://github.com/feross/standard)
# collect-json
***DEPRECATED: Please use [stream-read-all](https://github.com/75lb/stream-read-all) instead.***
<a name="module_collect-json"></a>
## collect-json
Returns a stream which becomes readable with a single value once all (valid) JSON is received.
<a name="exp_module_collect-json--collectJson"></a>
### collectJson([callback]) ⇒ [<code>Duplex</code>](https://nodejs.org/api/stream.html#stream_class_stream_duplex) ⏏
**Kind**: Exported function
| Param | Type | Description |
| --- | --- | --- |
| [callback] | <code>function</code> | called with the collected json data, once available. The value returned by the callback will be passed downstream. |
**Example**
An example command-line client script - JSON received at stdin is stamped with `received` then written to stdout.
```js
var collectJson = require("collect-json")
process.stdin
.pipe(collectJson(function(json){
json.received = true
return JSON.stringify(json)
}))
.on("error", function(err){
// input from stdin failed to parse
})
.pipe(process.stdout)
```
* * *
© 2015-21 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).