ldjson-stream

streaming line delimited json parser + serializer

BSD 5 个版本
安装
npm install ldjson-stream
yarn add ldjson-stream
pnpm add ldjson-stream
bun add ldjson-stream
README

ldjson-stream

streaming line delimited json parser + serializer

NPM

usage

var ldj = require('ldjson-stream')

ldj.parse()

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 ldj.parse({strict: false})

usage:

fs.createReadStream('data.txt')
  .pipe(ldj.parse())
  .on('data', function(obj) {
    // obj is a javascript object
  })

ldj.serialize()

returns a transform stream that accepts json objects and emits newline delimited json

example usage:

var serialize = ldj.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()

license

BSD

版本列表
1.2.1 2014-08-12
1.2.0 2014-08-09
1.1.0 2014-06-17
1.0.0 2014-06-15
0.0.1 2013-08-30