Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

concatjson

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concatjson

concatenated json streaming parser/serializer

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
209
decreased by-54.27%
Maintainers
1
Weekly downloads
 
Created
Source

#concatjson

travis npm

Standard JavaScript

Inspired by https://github.com/maxogden/ndjson

concatjson is concatenated JSON streaming parser/serializer for node.js.

###Install

npm i concatjson

###Usage

concatjson.parse()

  • @return {Stream.Transform} a Transform stream

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) => {
  // obj is a js object
}).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) => {
  // dat is stringified JSON
})

#####append object(s) to a file

const fs = require('fs')
const cj = require('concatjson')

// use flag 'a' for appending
var w = fs.createWriteStream('./somefile', {flags: 'a'})
var ser = cj.serialize()

// listen to all error events
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

Keywords

FAQs

Package last updated on 24 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc