flatten-json-pipe

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

Usage no npm install needed!

<script type="module">
  import flattenJsonPipe from 'https://cdn.skypack.dev/flatten-json-pipe';
</script>

README

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
  ]