在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dominictarr/JSONStream开源软件地址:https://github.com/dominictarr/JSONStream开源编程语言:JavaScript 100.0%开源软件介绍:JSONStreamstreaming JSON.parse and stringify install
examplevar request = require('request')
, JSONStream = require('JSONStream')
, es = require('event-stream')
request({url: 'http://isaacs.couchone.com/registry/_all_docs'})
.pipe(JSONStream.parse('rows.*'))
.pipe(es.mapSync(function (data) {
console.error(data)
return data
})) JSONStream.parse(path)parse stream of values that match a path JSONStream.parse('rows.*.doc') The If your keys have keys that include If you use an array, If If you want to have keys emitted, you can prefix your Examplesquery a couchdb view: curl -sS localhost:5984/tests/_all_docs&include_docs=true you will get something like this: {"total_rows":129,"offset":0,"rows":[
{ "id":"change1_0.6995461115147918"
, "key":"change1_0.6995461115147918"
, "value":{"rev":"1-e240bae28c7bb3667f02760f6398d508"}
, "doc":{
"_id": "change1_0.6995461115147918"
, "_rev": "1-e240bae28c7bb3667f02760f6398d508","hello":1}
},
{ "id":"change2_0.6995461115147918"
, "key":"change2_0.6995461115147918"
, "value":{"rev":"1-13677d36b98c0c075145bb8975105153"}
, "doc":{
"_id":"change2_0.6995461115147918"
, "_rev":"1-13677d36b98c0c075145bb8975105153"
, "hello":2
}
},
]} we are probably most interested in the create a var stream = JSONStream.parse(['rows', true, 'doc']) //rows, ANYTHING, doc
stream.on('data', function(data) {
console.log('received:', data);
});
//emits anything from _before_ the first match
stream.on('header', function (data) {
console.log('header:', data) // => {"total_rows":129,"offset":0}
}) awesome! In case you wanted the contents the doc emitted: var stream = JSONStream.parse(['rows', true, 'doc', {emitKey: true}]) //rows, ANYTHING, doc, items in docs with keys
stream.on('data', function(data) {
console.log('key:', data.key);
console.log('value:', data.value);
}); You can also emit the path: var stream = JSONStream.parse(['rows', true, 'doc', {emitPath: true}]) //rows, ANYTHING, doc, items in docs with keys
stream.on('data', function(data) {
console.log('path:', data.path);
console.log('value:', data.value);
}); recursive patterns (..)
{
"total": 5,
"docs": [
{
"key": {
"value": 0,
"some": "property"
}
},
{"value": 1},
{"value": 2},
{"blbl": [{}, {"a":0, "b":1, "value":3}, 10]},
{"value": 4}
]
} JSONStream.parse(pattern, map)provide a function that can be used to map or filter
the json output.
JSONStream.stringify(open, sep, close)Create a writable stream. you may pass in custom If you call If you only write one item this will be valid JSON. If you write many items,
you can use a JSONStream.stringifyObject(open, sep, close)Very much like Accordingly, When you unix toolquery npm to see all the modules that browserify has ever depended on. curl https://registry.npmjs.org/browserify | JSONStream 'versions.*.dependencies' numbersnumbers will be emitted as numbers. huge numbers that cannot be represented in memory as javascript numbers will be emitted as strings. cf https://github.com/creationix/jsonparse/commit/044b268f01c4b8f97fb936fc85d3bcfba179e5bb for details. Acknowlegementsthis module depends on https://github.com/creationix/jsonparse by Tim Caswell and also thanks to Florent Jaby for teaching me about parsing with: https://github.com/Floby/node-json-streams licenseDual-licensed under the MIT License or the Apache License, version 2.0 |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论