Gathering detailed insights and metrics for minipass-json-stream
Gathering detailed insights and metrics for minipass-json-stream
Gathering detailed insights and metrics for minipass-json-stream
Gathering detailed insights and metrics for minipass-json-stream
npm install minipass-json-stream
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
99.5
Quality
76
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
816,826,677
Last Day
185,246
Last Week
3,738,270
Last Month
16,171,325
Last Year
208,504,546
NOASSERTION License
3 Stars
12 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Jun 15, 2025
Minified
Minified + Gzipped
Latest Version
1.0.2
Package Id
minipass-json-stream@1.0.2
Unpacked Size
14.11 kB
Size
5.16 kB
File Count
4
NPM Version
6.14.18
Node Version
14.21.3
Published on
Jul 28, 2024
Cumulative downloads
Total Downloads
Last Day
-15.7%
185,246
Compared to previous day
Last Week
-9.9%
3,738,270
Compared to previous week
Last Month
4%
16,171,325
Compared to previous month
Last Year
-15.5%
208,504,546
Compared to previous year
2
Like JSONStream, but using Minipass streams
npm install minipass-json-stream
1 2const request = require('request') 3const JSONStream = require('minipass-json-stream') 4const es = require('event-stream') 5 6request({url: 'http://isaacs.couchone.com/registry/_all_docs'}) 7 .pipe(JSONStream.parse('rows.*')) 8 .pipe(es.mapSync(function (data) { 9 console.error(data) 10 return data 11 }))
Create a new stream. This is a minipass stream
that is always set in objectMode
. It emits objects parsed out of
string/buffer JSON input that match the supplied path
option.
Return a new JSONStream object to stream values that match a path.
(Equivalent to new JSONStream({path})
.)
1JSONStream.parse('rows.*.doc')
The ..
operator is the recursive descent operator from
JSONPath, which will match a
child at any depth (see examples below).
If your keys have keys that include .
or *
etc, use an array instead.
['row', true, /^doc/]
.
If you use an array, RegExp
s, booleans, and/or functions. The ..
operator is also available in array representation, using {recurse: true}
. any object that matches the path will be emitted as 'data' (and
pipe
d down stream)
If path
is empty or null, no 'data' events are emitted.
If you want to have keys emitted, you can prefix your *
operator with
$
: obj.$*
- in this case the data passed to the stream is an object
with a key
holding the key and a value
property holding the data.
query a couchdb view:
1curl -sS localhost:5984/tests/_all_docs&include_docs=true
you will get something like this:
1{"total_rows":129,"offset":0,"rows":[ 2 { "id":"change1_0.6995461115147918" 3 , "key":"change1_0.6995461115147918" 4 , "value":{"rev":"1-e240bae28c7bb3667f02760f6398d508"} 5 , "doc":{ 6 "_id": "change1_0.6995461115147918" 7 , "_rev": "1-e240bae28c7bb3667f02760f6398d508","hello":1} 8 }, 9 { "id":"change2_0.6995461115147918" 10 , "key":"change2_0.6995461115147918" 11 , "value":{"rev":"1-13677d36b98c0c075145bb8975105153"} 12 , "doc":{ 13 "_id":"change2_0.6995461115147918" 14 , "_rev":"1-13677d36b98c0c075145bb8975105153" 15 , "hello":2 16 } 17 }, 18]}
we are probably most interested in the rows.*.doc
create a JSONStream
that parses the documents from the feed like this:
1var stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc 2 3stream.on('data', function(data) { 4 console.log('received:', data); 5}); 6 7//emits anything from _before_ the first match 8stream.on('header', function (data) { 9 console.log('header:', data) // => {"total_rows":129,"offset":0} 10})
awesome!
In case you wanted the contents the doc emitted:
1// equivalent to: 'rows.*.doc.$*' 2var stream = JSONStream.parse([ 3 'rows', 4 true, 5 'doc', 6 {emitKey: true} 7]) //rows, ANYTHING, doc, items in docs with keys 8 9stream.on('data', function(data) { 10 console.log('key:', data.key); 11 console.log('value:', data.value); 12});
You can also emit the path:
1var stream = JSONStream.parse([ 2 'rows', 3 true, 4 'doc', 5 {emitPath: true} 6]) //rows, ANYTHING, doc, items in docs with keys 7 8stream.on('data', function(data) { 9 console.log('path:', data.path); 10 console.log('value:', data.value); 11});
JSONStream.parse('docs..value')
(or JSONStream.parse(['docs', {recurse: true}, 'value'])
using an array)
will emit every value
object that is a child, grand-child, etc. of the
docs
object. In this example, it will match exactly 5 times at various depth
levels, emitting 0, 1, 2, 3 and 4 as results.
1{ 2 "total": 5, 3 "docs": [ 4 { 5 "key": { 6 "value": 0, 7 "some": "property" 8 } 9 }, 10 {"value": 1}, 11 {"value": 2}, 12 {"blbl": [{}, {"a":0, "b":1, "value":3}, 10]}, 13 {"value": 4} 14 ] 15}
(Equivalent to new JSONStream({ pattern, map })
)
provide a function that can be used to map or filter
the json output. map
is passed the value at that node of the pattern,
if map
return non-nullish (anything but null
or undefined
)
that value will be emitted in the stream. If it returns a nullish value,
nothing will be emitted.
JSONStream
also emits 'header'
and 'footer'
events,
the 'header'
event contains anything in the output that was before
the first match, and the 'footer'
, is anything after the last match.
This module is a fork of JSONStream by Dominic Tarr, modified and redistributed under the terms of the MIT license.
this module depends on https://github.com/creationix/jsonparse by Tim Caswell
No vulnerabilities found.
No security vulnerabilities found.