0.0.2 • Published 9 years ago

flatten-json-pipe v0.0.2

Weekly downloads
2
License
AGPL-3.0
Repository
github
Last release
9 years ago

#flatten-json-pipe

Pipe JSON in, get it flattened on the way out.

Build Status Dependencies License

##Run

Install with npm.

$ npm install flatten-json-pipe -g

Pipe through passing an optional delimiter.

$ echo '{"A":{"name":"Peter"},"B":{"val":[\"a\",\"b\"]}}' | flatten-json-pipe '.'

You get the following back:

{
  "A.name": "Peter",
  "B.val.0": "a",
  "B.val.1": "b"
}

##Source

_      = require 'highland'
ndjson = require 'ndjson'
flat   = require 'flat'

module.exports = (delimiter='.') ->
  through = (obj) -> flat obj, { delimiter }

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