lib/jsonarray.js
function JsonArray (options) {
  if (!(this instanceof JsonArray)) {
    return new JsonArray(options)
  }

  this.options = Object.assign({}, options, { objectMode: true })

  this.count = 0
  this.map = ['[\n', ',\n', '\n]\n']
  if (this.options.validJson === false) {
    this.map = ['', '\n', '\n']
  }

  if (this.options.stringify) {
    this._transform = this._stringify
    this._flush = function (done) {
      this.push(this.map[2])
      setTimeout(function () {
        done()
      }, 2)
    }
  } else {
    this._transform = this._parse
  }

  Transform.call(this, _omit(this.options, ['error', 'validJson', 'stringify']))

  return this
}
function JsonArray (options) {
  if (!(this instanceof JsonArray)) {
    return new JsonArray(options)
  }

  this.options = Object.assign({}, options, { objectMode: true })

  this.count = 0
  this.map = ['[\n', ',\n', '\n]\n']
  if (this.options.validJson === false) {
    this.map = ['', '\n', '\n']
  }

  if (this.options.stringify) {
    this._transform = this._stringify
    this._flush = function (done) {
      this.push(this.map[2])
      setTimeout(function () {
        done()
      }, 2)
    }
  } else {
    this._transform = this._parse
  }

  Transform.call(this, _omit(this.options, ['error', 'validJson', 'stringify']))

  return this
}
function JsonArray ( options ) { if ( ! ( this instanceof JsonArray ) ) { return new JsonArray ( options ) } this . options = Object . assign ( { } , options , { objectMode : true } ) this . count = 0 this . map = [ '[\n' , ',\n' , '\n]\n' ] if ( this . options . validJson === false ) { this . map = [ '' , '\n' , '\n' ] } if ( this . options . stringify ) { this . _transform = this . _stringify this . _flush = function ( done ) { this . push ( this . map [ 2 ] ) setTimeout ( function ( ) { done ( ) } , 2 ) } } else { this . _transform = this . _parse } Transform . call ( this , _omit ( this . options , [ 'error' , 'validJson' , 'stringify' ] ) ) return this }
JSON.parse a line and push as object down the pipe.

If `stringify: true` is set, a received object is stringified with JSON.stringify
The output of the stream will be a valid JSON array.

NOTE: Requires that the stream is split beforehand using `Split` or `SplitLine`.

@constructor
@param {Object} [options] - Stream Options `{encoding, highWaterMark, decodeStrings, ...}`
@param {Boolean} options.error - Emit parsing errors as `Error` objects. Default=false.
@param {Boolean} options.validJson - Write out a valid json file, which can be parsed as a whole. Default=true.
@param {Boolean} options.stringify - Transforms an object into a string using JSON.stringify. Default=false.
@return {Transform} A transform stream
JSON . parse a line and push as object down the pipe .