{"_id":"@alexrmturner/json-stream","_rev":"1-1307d09b20918b32b9d26ee99eb37814","name":"@alexrmturner/json-stream","dist-tags":{"latest":"1.3.7"},"versions":{"1.3.6":{"name":"@alexrmturner/json-stream","version":"1.3.6","keywords":["json","stream","streaming","parser","async","parsing"],"author":{"url":"http://bit.ly/dominictarr","name":"Dominic Tarr","email":"dominic.tarr@gmail.com"},"license":"(MIT OR Apache-2.0)","_id":"@alexrmturner/json-stream@1.3.6","maintainers":[{"name":"alexrmturner","email":"alexrmturner@gmail.com"}],"homepage":"http://github.com/armtuk/JSONStream","bugs":{"url":"https://github.com/armtuk/JSONStream/issues"},"bin":{"json-stream":"bin.js"},"dist":{"shasum":"b544cf9f846be306ec2e860c9da9ae6b4de993e0","tarball":"https://registry.npmjs.org/@alexrmturner/json-stream/-/json-stream-1.3.6.tgz","fileCount":40,"integrity":"sha512-zbzKaejtKwfoTKdcR/8/OELUL/WHhjf8uWbP+HClz+h7kdb8eybMa3mBN+mATzSuMzabXQR1gzXWY4Siv7IOcA==","signatures":[{"sig":"MEQCIAfUSXrDq3HnN8Am9IbNkge9IXVRC9c4EtLVMiVKHd2MAiBrFllLsLlNykZx+Qbbm5jMYGfEhdLqyPBr6fcd2yRnWQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":410844},"engines":{"node":"*"},"gitHead":"f22f6646747e3f5118b21b64ad568342bdd0e2c5","scripts":{"test":"node test/run.js"},"_npmUser":{"name":"alexrmturner","email":"alexrmturner@gmail.com"},"repository":{"url":"git://github.com/armtuk/JSONStream.git","type":"git"},"_npmVersion":"10.7.0","description":"Modified version of JSON Stream to parse in objects that have null values at the root level of an object","directories":{},"_nodeVersion":"20.15.1","dependencies":{"through":">=2.2.7 <3","jsonparse":"^1.2.0"},"_hasShrinkwrap":false,"devDependencies":{"tape":"~2.12.3","it-is":"~1","trees":"~0.0.3","render":"~0.1.1","assertions":"~2.2.2","event-stream":"~0.7.0"},"optionalDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/json-stream_1.3.6_1723694631353_0.48123528916711966","host":"s3://npm-registry-packages"}},"1.3.7":{"name":"@alexrmturner/json-stream","version":"1.3.7","description":"Modified version of JSON Stream to parse in objects that have null values at the root level of an object","homepage":"http://github.com/armtuk/JSONStream","repository":{"type":"git","url":"git://github.com/armtuk/JSONStream.git"},"license":"(MIT OR Apache-2.0)","keywords":["json","stream","streaming","parser","async","parsing"],"dependencies":{"jsonparse":"^1.2.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":{"json-stream":"bin.js"},"author":{"name":"Dominic Tarr","email":"dominic.tarr@gmail.com","url":"http://bit.ly/dominictarr"},"scripts":{"test":"node test/run.js"},"optionalDependencies":{},"engines":{"node":"*"},"_id":"@alexrmturner/json-stream@1.3.7","gitHead":"f22f6646747e3f5118b21b64ad568342bdd0e2c5","bugs":{"url":"https://github.com/armtuk/JSONStream/issues"},"_nodeVersion":"20.15.1","_npmVersion":"10.7.0","dist":{"integrity":"sha512-JyIUM/jlQpoTUMDLL2FI6H/TY83WC6gmaYEPeoC/QI+H6pDiN5X1EiZNo16QvaHSurSYzmVa+QZgq02ek9J9eA==","shasum":"821b8cce8432051f1e7b87d139eda3e1cffcb980","tarball":"https://registry.npmjs.org/@alexrmturner/json-stream/-/json-stream-1.3.7.tgz","fileCount":40,"unpackedSize":411663,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCBzX9fSInU6TyDHpY2D9kb3c7lQN0YNwMNYtg5+IQVkgIgDDAokjUpMs4txVlADDatY8DeS+S33P8uOSeQc+pTfPI="}]},"_npmUser":{"name":"alexrmturner","email":"alexrmturner@gmail.com"},"directories":{},"maintainers":[{"name":"alexrmturner","email":"alexrmturner@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/json-stream_1.3.7_1723695227330_0.354187092660438"},"_hasShrinkwrap":false}},"time":{"created":"2024-08-15T04:03:51.248Z","modified":"2024-08-15T04:13:47.726Z","1.3.6":"2024-08-15T04:03:51.503Z","1.3.7":"2024-08-15T04:13:47.560Z"},"bugs":{"url":"https://github.com/armtuk/JSONStream/issues"},"author":{"name":"Dominic Tarr","email":"dominic.tarr@gmail.com","url":"http://bit.ly/dominictarr"},"license":"(MIT OR Apache-2.0)","homepage":"http://github.com/armtuk/JSONStream","keywords":["json","stream","streaming","parser","async","parsing"],"repository":{"type":"git","url":"git://github.com/armtuk/JSONStream.git"},"description":"Modified version of JSON Stream to parse in objects that have null values at the root level of an object","maintainers":[{"name":"alexrmturner","email":"alexrmturner@gmail.com"}],"readme":"# json-stream \n\nStreaming JSON.parse and stringify\n\nBased on dominictarr's JSONStream, this version has been modified to handle null values as significant.\nhttps://www.npmjs.com/package/JSONStream\n\n### Details \n\nNote about this particular version. Objects structured:\n\n```\n{ a: 1, b: null } \n```\n\nwould be read in and be missing the b key from the top level object in the original version. \nFor the purposes of reading in objects where the null value is significant, this needed an adjustment.\n\nThis version of this library will read in the object with null values correctly. It\ndoes mean that it will ignore `undefined` values however as I replaced the nullish behaviour\nwith undefined behaviour. For purposes of reading in data that was serialized originally from\na SQL database, this is preferable. The test cases in the package have been updated to reflect this.\n\n## install\n```npm install @alexrmturner/json-stream```\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\nIf 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.\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//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\nvar stream = JSONStream.parse(['rows', true, 'doc', {emitKey: true}]) //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```\n\nYou can also emit the path:\n\n``` js\nvar stream = JSONStream.parse(['rows', true, 'doc', {emitPath: true}]) //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\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` 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## 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\nnumbers will be emitted as numbers.\nhuge numbers that cannot be represented in memory as javascript numbers will be emitted as strings.\ncf https://github.com/creationix/jsonparse/commit/044b268f01c4b8f97fb936fc85d3bcfba179e5bb for details.\n\n## Acknowlegements\n\nbased originally on https://www.npmjs.com/package/JSONStream\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\nDual-licensed under the MIT License or the Apache License, version 2.0\n\n","readmeFilename":"readme.markdown"}