Bakhtina Sofya b84cb877be 1st comm | 2 週間 前 | |
---|---|---|
.. | ||
.npmignore | 2 週間 前 | |
cli.js | 2 週間 前 | |
collaborators.md | 2 週間 前 | |
index.js | 2 週間 前 | |
package.json | 2 週間 前 | |
readme.md | 2 週間 前 | |
test.js | 2 週間 前 |
streaming newline delimited json parser + serializer. Available as a JS API or a command line tool
var ndjson = require('ndjson')
returns a transform stream that accepts newline delimited json and emits objects
example newline delimited json:
data.txt
:
{"foo": "bar"}
{"hello": "world"}
If you want to discard non-valid JSON messages, you can call ndjson.parse({strict: false})
usage:
fs.createReadStream('data.txt')
.pipe(ndjson.parse())
.on('data', function(obj) {
// obj is a javascript object
})
returns a transform stream that accepts json objects and emits newline delimited json
example usage:
var serialize = ndjson.serialize()
serialize.on('data', function(line) {
// line is a line of stringified JSON with a newline delimiter at the end
})
serialize.write({"foo": "bar"})
serialize.end()
BSD-3-Clause