{"_id":"minipass-json-stream","_rev":"146447","name":"minipass-json-stream","description":"Like JSONStream, but using Minipass streams","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"isaacs","email":""}],"time":{"modified":"2021-06-03T11:30:03.000Z","created":"2019-10-01T19:05:27.280Z","1.0.1":"2019-10-01T19:06:20.951Z","1.0.0":"2019-10-01T19:05:27.280Z"},"users":{},"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"repository":{"type":"git","url":"git+https://github.com/npm/minipass-json-stream.git"},"versions":{"1.0.1":{"name":"minipass-json-stream","version":"1.0.1","description":"Like JSONStream, but using Minipass streams","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"MIT","scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"check-coverage":true},"devDependencies":{"JSONStream":"^1.3.5","tap":"^14.6.9"},"dependencies":{"jsonparse":"^1.3.1","minipass":"^3.0.0"},"repository":{"type":"git","url":"git+https://github.com/npm/minipass-json-stream.git"},"keywords":["stream","json","parse","minipass","JSONStream"],"gitHead":"38826f1f7ccc32023afc603c218fb6f2a15b407e","bugs":{"url":"https://github.com/npm/minipass-json-stream/issues"},"homepage":"https://github.com/npm/minipass-json-stream#readme","_id":"minipass-json-stream@1.0.1","_nodeVersion":"12.8.1","_npmVersion":"6.12.0-next.0","dist":{"shasum":"7edbb92588fbfc2ff1db2fc10397acb7b6b44aa7","size":4944,"noattachment":false,"key":"/minipass-json-stream/-/minipass-json-stream-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/minipass-json-stream/download/minipass-json-stream-1.0.1.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/minipass-json-stream_1.0.1_1569956780798_0.737651803293434"},"_hasShrinkwrap":false,"publish_time":1569956780951,"_cnpm_publish_time":1569956780951},"1.0.0":{"name":"minipass-json-stream","version":"1.0.0","description":"Like JSONStream, but using Minipass streams","author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://izs.me"},"license":"MIT","scripts":{"test":"tap","snap":"tap","preversion":"npm test","postversion":"npm publish","postpublish":"git push origin --follow-tags"},"tap":{"check-coverage":true},"devDependencies":{"JSONStream":"^1.3.5","tap":"^14.6.9"},"dependencies":{"jsonparse":"^1.3.1","minipass":"^3.0.0"},"repository":{"type":"git","url":"git+https://github.com/npm/minipass-json-stream.git"},"keywords":["stream","json","parse","minipass","JSONStream"],"gitHead":"7cf670ea29c50db66c62a803231d5dd6c7674e0c","bugs":{"url":"https://github.com/npm/minipass-json-stream/issues"},"homepage":"https://github.com/npm/minipass-json-stream#readme","_id":"minipass-json-stream@1.0.0","_nodeVersion":"12.8.1","_npmVersion":"6.12.0-next.0","dist":{"shasum":"0d74117b7133336ddedf784646636c11ae365e13","size":35899,"noattachment":false,"key":"/minipass-json-stream/-/minipass-json-stream-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/minipass-json-stream/download/minipass-json-stream-1.0.0.tgz"},"maintainers":[{"name":"isaacs","email":""}],"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/minipass-json-stream_1.0.0_1569956727149_0.943201609487669"},"_hasShrinkwrap":false,"publish_time":1569956727280,"_cnpm_publish_time":1569956727280}},"readme":"# minipass-json-stream\n\nLike [JSONStream](http://npm.im/JSONStream), but using Minipass streams\n\n## install\n\n```\nnpm install minipass-json-stream\n```\n\n## example\n\n```js\n\nconst request = require('request')\nconst JSONStream = require('minipass-json-stream')\nconst es = require('event-stream')\n\nrequest({url: 'http://isaacs.couchone.com/registry/_all_docs'})\n  .pipe(JSONStream.parse('rows.*'))\n  .pipe(es.mapSync(function (data) {\n    console.error(data)\n    return data\n  }))\n```\n\n## new JSONStream(options)\n\nCreate a new stream.  This is a [minipass](http://npm.im/minipass) stream\nthat is always set in `objectMode`.  It emits objects parsed out of\nstring/buffer JSON input that match the supplied `path` option.\n\n## JSONStream.parse(path)\n\nReturn a new JSONStream object to stream values that match a path.\n\n(Equivalent to `new JSONStream({path})`.)\n\n``` js\nJSONStream.parse('rows.*.doc')\n```\n\nThe `..` operator is the recursive descent operator from\n[JSONPath](http://goessner.net/articles/JsonPath/), which will match a\nchild at any depth (see examples below).\n\nIf your keys have keys that include `.` or `*` etc, use an array instead.\n`['row', true, /^doc/]`.\n\nIf you use an array, `RegExp`s, booleans, and/or functions. The `..`\noperator is also available in array representation, using `{recurse:\ntrue}`.  any object that matches the path will be emitted as 'data' (and\n`pipe`d down stream)\n\nIf `path` is empty or null, no 'data' events are emitted.\n\nIf you want to have keys emitted, you can prefix your `*` operator with\n`$`: `obj.$*` - in this case the data passed to the stream is an object\nwith a `key` holding the key and a `value` property holding the data.\n\n### Examples\n\nquery a couchdb view:\n\n``` bash\ncurl -sS localhost:5984/tests/_all_docs&include_docs=true\n```\nyou will get something like this:\n\n``` js\n{\"total_rows\":129,\"offset\":0,\"rows\":[\n  { \"id\":\"change1_0.6995461115147918\"\n  , \"key\":\"change1_0.6995461115147918\"\n  , \"value\":{\"rev\":\"1-e240bae28c7bb3667f02760f6398d508\"}\n  , \"doc\":{\n      \"_id\":  \"change1_0.6995461115147918\"\n    , \"_rev\": \"1-e240bae28c7bb3667f02760f6398d508\",\"hello\":1}\n  },\n  { \"id\":\"change2_0.6995461115147918\"\n  , \"key\":\"change2_0.6995461115147918\"\n  , \"value\":{\"rev\":\"1-13677d36b98c0c075145bb8975105153\"}\n  , \"doc\":{\n      \"_id\":\"change2_0.6995461115147918\"\n    , \"_rev\":\"1-13677d36b98c0c075145bb8975105153\"\n    , \"hello\":2\n    }\n  },\n]}\n```\n\nwe are probably most interested in the `rows.*.doc`\n\ncreate a `JSONStream` that parses the documents from the feed like this:\n\n``` js\nvar stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc\n\nstream.on('data', function(data) {\n  console.log('received:', data);\n});\n\n//emits anything from _before_ the first match\nstream.on('header', function (data) {\n  console.log('header:', data) // => {\"total_rows\":129,\"offset\":0}\n})\n```\n\nawesome!\n\nIn case you wanted the contents the doc emitted:\n\n``` js\n// equivalent to: 'rows.*.doc.$*'\nvar stream = JSONStream.parse([\n  'rows',\n  true,\n  'doc',\n  {emitKey: true}\n]) //rows, ANYTHING, doc, items in docs with keys\n\nstream.on('data', function(data) {\n  console.log('key:', data.key);\n  console.log('value:', data.value);\n});\n```\n\nYou can also emit the path:\n\n``` js\nvar stream = JSONStream.parse([\n  'rows',\n  true,\n  'doc',\n  {emitPath: true}\n]) //rows, ANYTHING, doc, items in docs with keys\n\nstream.on('data', function(data) {\n  console.log('path:', data.path);\n  console.log('value:', data.value);\n});\n```\n\n### recursive patterns (..)\n\n`JSONStream.parse('docs..value')` \n(or `JSONStream.parse(['docs', {recurse: true}, 'value'])` using an array)\nwill emit every `value` object that is a child, grand-child, etc. of the \n`docs` object. In this example, it will match exactly 5 times at various depth\nlevels, emitting 0, 1, 2, 3 and 4 as results.\n\n```js\n{\n  \"total\": 5,\n  \"docs\": [\n    {\n      \"key\": {\n        \"value\": 0,\n        \"some\": \"property\"\n      }\n    },\n    {\"value\": 1},\n    {\"value\": 2},\n    {\"blbl\": [{}, {\"a\":0, \"b\":1, \"value\":3}, 10]},\n    {\"value\": 4}\n  ]\n}\n```\n\n## JSONStream.parse(pattern, map)\n\n(Equivalent to `new JSONStream({ pattern, map })`)\n\nprovide a function that can be used to map or filter\nthe json output. `map` is passed the value at that node of the pattern,\nif `map` return non-nullish (anything but `null` or `undefined`)\nthat value will be emitted in the stream. If it returns a nullish value,\nnothing will be emitted.\n\n`JSONStream` also emits `'header'` and `'footer'` events,\nthe `'header'` event contains anything in the output that was before\nthe first match, and the `'footer'`, is anything after the last match.\n\n## Acknowlegements\n\nThis module is a fork of [JSONStream](http://npm.im/JSONStream) by Dominic\nTarr, modified and redistributed under the terms of the MIT license.\n\nthis module depends on https://github.com/creationix/jsonparse\nby Tim Caswell\n","_attachments":{},"homepage":"https://github.com/npm/minipass-json-stream#readme","bugs":{"url":"https://github.com/npm/minipass-json-stream/issues"},"license":"MIT"}