dominictarr/JSONStream được TopGit xếp vào nhóm dự án mã nguồn mở, với 1.9k sao trên GitHub, viết chủ yếu bằng JavaScript. rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
var 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 .. 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, RegExps, 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 piped 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.
create a Stream that parses the documents from the feed like this:
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 (..)
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.
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.
JSONStream.stringify(open, sep, close)
Create a writable stream.
you may pass in custom open, close, and seperator strings.
But, by default, JSONStream.stringify() will create an array,
(with default options open='[\n', sep='\n,\n', close='\n]\n')
If you call JSONStream.stringify(false)
the elements will only be seperated by a newline.
If you only write one item this will be valid JSON.
If you write many items,
you can use a RegExp to split it into valid chunks.
JSONStream.stringifyObject(open, sep, close)
Very much like JSONStream.stringify,
but creates a writable stream for objects instead of arrays.
numbers 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.
Acknowlegements
this 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
license
Dual-licensed under the MIT License or the Apache License, version 2.0
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/dominictarr/JSONStream là nguồn chính thức.
dominictarr/JSONStream có bao nhiêu sao?
dominictarr/JSONStream có 1.9k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/dominictarr/JSONStream. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
dominictarr/JSONStream có tag gì không?
Bản đồng bộ chưa ghi nhận topic GitHub nào cho dominictarr/JSONStream. GitHub topics hiển thị ở thanh bên phải trang repo — đó là nơi đáng kiểm tra nhất.
dominictarr/JSONStream còn đang phát triển không?
Commit gần nhất trên dominictarr/JSONStream là 8.1 năm trước (theo timestamp GitHub). Repo có 162 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
dominictarr/JSONStream viết bằng ngôn ngữ gì?
dominictarr/JSONStream chủ yếu viết bằng JavaScript. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
JSONStream có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về JSONStream.