{"_id":"jsonstream","_rev":"81657","name":"jsonstream","description":"rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)","dist-tags":{"latest":"1.0.3"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"time":{"modified":"2021-06-03T10:26:03.000Z","created":"2015-04-30T00:17:50.625Z","1.0.3":"2015-04-30T00:17:50.625Z"},"users":{"thomas-jensen":true,"wenbing":true,"scottfreecode":true},"author":{"name":"Dominic Tarr","email":"dominic.tarr@gmail.com","url":"http://bit.ly/dominictarr"},"repository":{"type":"git","url":"git://github.com/dominictarr/JSONStream.git"},"versions":{"1.0.3":{"name":"jsonstream","version":"1.0.3","description":"rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)","homepage":"http://github.com/dominictarr/JSONStream","repository":{"type":"git","url":"git://github.com/dominictarr/JSONStream.git"},"keywords":["json","stream","streaming","parser","async","parsing"],"dependencies":{"jsonparse":"~1.0.0","through":">=2.2.7 <3"},"devDependencies":{"it-is":"~1","assertions":"~2.2.2","render":"~0.1.1","trees":"~0.0.3","event-stream":"~0.7.0","tape":"~2.12.3"},"bin":{"jsonstream":"./index.js"},"author":{"name":"Dominic Tarr","email":"dominic.tarr@gmail.com","url":"http://bit.ly/dominictarr"},"scripts":{"test":"set -e; for t in test/*.js; do echo '***' $t '***'; node $t; done"},"optionalDependencies":{},"engines":{"node":"*"},"gitHead":"ef6a0faed2340a38dbe961d460c863426dde1966","bugs":{"url":"https://github.com/dominictarr/JSONStream/issues"},"_id":"jsonstream@1.0.3","_shasum":"ff2d49c4f479b5bbcdf9f9e56c841cf87f0efa1d","_from":".","_npmVersion":"2.4.1","_nodeVersion":"0.10.35","_npmUser":{"name":"dominictarr","email":"dominic.tarr@gmail.com"},"maintainers":[{"name":"nopersonsmodules","email":"nopersonsmodules@gmail.com"}],"dist":{"shasum":"ff2d49c4f479b5bbcdf9f9e56c841cf87f0efa1d","size":136683,"noattachment":false,"key":"/jsonstream/-/jsonstream-1.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/jsonstream/download/jsonstream-1.0.3.tgz"},"directories":{},"publish_time":1430353070625,"_cnpm_publish_time":1430353070625,"deprecated":"use JSONStream instead","_hasShrinkwrap":false}},"readme":"# JSONStream\n\nstreaming JSON.parse and stringify\n\n![](https://secure.travis-ci.org/dominictarr/JSONStream.png?branch=master)\n\n## example\n\n``` js\n\nvar request = require('request')\n  , JSONStream = require('JSONStream')\n  , 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## JSONStream.parse(path)\n\nparse stream of values that match a path\n\n``` js\n  JSONStream.parse('rows.*.doc')\n```\n\nThe `..` operator is the recursive descent operator from [JSONPath](http://goessner.net/articles/JsonPath/), which will match a child 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 `..` operator is also available in array representation, using `{recurse: true}`.\nany object that matches the path will be emitted as 'data' (and `pipe`d down stream)\n\nIf `path` is empty or null, no 'data' events are emitted.\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```\n\nwe are probably most interested in the `rows.*.doc`\n\ncreate a `Stream` 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```\nawesome!\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\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.stringify(open, sep, close)\n\nCreate a writable stream.\n\nyou may pass in custom `open`, `close`, and `seperator` strings.\nBut, by default, `JSONStream.stringify()` will create an array,\n(with default options `open='[\\n', sep='\\n,\\n', close='\\n]\\n'`)\n\nIf you call `JSONStream.stringify(false)`\nthe elements will only be seperated by a newline.\n\nIf you only write one item this will be valid JSON.\n\nIf you write many items,\nyou can use a `RegExp` to split it into valid chunks.\n\n## JSONStream.stringifyObject(open, sep, close)\n\nVery much like `JSONStream.stringify`,\nbut creates a writable stream for objects instead of arrays.\n\nAccordingly, `open='{\\n', sep='\\n,\\n', close='\\n}\\n'`.\n\nWhen you `.write()` to the stream you must supply an array with `[ key, data ]`\nas the first argument.\n\n## unix tool\n\nquery npm to see all the modules that browserify has ever depended on.\n\n``` bash\ncurl https://registry.npmjs.org/browserify | JSONStream 'versions.*.dependencies'\n```\n\n## numbers\n\nThere are occasional problems parsing and unparsing very precise numbers.\n\nI have opened an issue here:\n\nhttps://github.com/creationix/jsonparse/issues/2\n\n+1\n\n## Acknowlegements\n\nthis module depends on https://github.com/creationix/jsonparse\nby Tim Caswell\nand also thanks to Florent Jaby for teaching me about parsing with:\nhttps://github.com/Floby/node-json-streams\n\n## license\n\nMIT / APACHE2\n","_attachments":{},"homepage":"http://github.com/dominictarr/JSONStream","bugs":{"url":"https://github.com/dominictarr/JSONStream/issues"}}