ldjson-keys

Pipe LDJSON in, get all of the keys found out.

Usage no npm install needed!

<script type="module">
  import ldjsonKeys from 'https://cdn.skypack.dev/ldjson-keys';
</script>

README

ldjson-keys

Pipe LDJSON in, get all of the keys found out.

This is useful in conjunction with maxogden/csv-write-stream that reads CSV columns from first row/object only.

Build Status Dependencies License

Run

Install with npm.

$ npm install ldjson-to-csv -g

By default you get new-line delimited output:

$ echo '{"col1":1}\n{"col2":2}' | ldjson-to-csv
# col1
# col2

Source

_       = require 'highland'
ndjson  = require 'ndjson'
{ EOL } = require 'os'

module.exports = ->
  keys = {}

  through = (obj) ->
    _ (push, next) ->
      for k of obj when k not of keys
        keys[k] = null
        push null, k + EOL
      push null, _.nil

  _.pipeline.apply _, [
    do _
    do ndjson.parse
    _.map through
    _.parallel 50
  ]