Skip to content

davidguttman/serialize-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

serialize-stream

Stream json, ndjson, or csv.

This is useful if you have an API and want to stream different formats depending on a param.

Uses csv-write-stream and JSONStream under the hood.

Example

var ss = require('serialize-stream')

ss('csv')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// a,b,c
// 1,2,3

ss('json')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// [
// {"a":1,"b":2,"c":3}
// ]

ss('ndjson')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// {"a":1,"b":2,"c":3}

API

ss(format, [opts])

  • format is one of: 'csv', 'json', or 'ndjson'.

  • opts defaults:

{
  compact: false, // csv: will remove undefined keys (like in json)
  flatten: false // csv: will flatten nested objects using `object2dot`[1]
}

[1] object2dot

License

MIT

About

Stream json, ndjson, or csv.

Resources

Stars

Watchers

Forks

Packages

No packages published