#concatjson
Inspired by https://github.com/maxogden/ndjson
concatjson
is concatenated JSON streaming parser/serializer for node.js.
###Install
npm i concatjson
###Usage
concatjson.parse()
parses concatenated JSON stream and emits javascript objects.
somefile (contains concatenated JSON objects)
{"foo":"bar"}{"qux":"corge"}{"baz":{"waldo":"thud"}}
const cj = require('concatjson')
fs.createReadStream('./somefile').pipe(cj.parse()).on('error', (err) => {
console.error(err)
}).on('data', (obj) => {
}).on('end', () => {
console.log('finished successfully.')
})
concatjson.serialize()
alias: concatjson.stringify()
accepts objects and emits stringified JSON objects.
const cj = require('concatjson')
var ser = cj.serialize()
ser.write({foo: 'bar'})
ser.end()
ser.on('data', (dat) => {
})
#####append object(s) to a file
const fs = require('fs')
const cj = require('concatjson')
var w = fs.createWriteStream('./somefile', {flags: 'a'})
var ser = cj.serialize()
w.on('error', (err) => {
console.error(err)
})
ser.on('error', (err) => {
console.error(err)
})
ser.write({foo: 'bar'})
ser.end()
ser.pipe(w).on('finish', () => {
console.log('appended successfully.')
})
###License
MIT