2.0.1 • Published 8 years ago

jsonmap v2.0.1

Weekly downloads
6
License
BSD-2-Clause
Repository
github
Last release
8 years ago

jsonmap

NPM

streaming command line newline-delimited json transformer utility

you must pipe newline-delimited JSON data in (one JSON stringified object per line). you will receive the same format out

installation

$ npm install jsonmap -g

usage

this will be each line of JSON that gets parsed out of the incoming newline-delimited json stream. you can also use _ as a shorthand for this, and you are allowed to require things.

there are two 'modes', the first is where you modify this:

$ echo '{"foo": "bar"}\n{"baz": "taco"}' | jsonmap "this.pizza = 1"
{"foo":"bar","pizza":1}
{"baz":"taco","pizza":1}

the second mode is where you return a new object:

$ echo '{"foo": "bar", "cat": "yes"}\n{"baz": "taco", "cat": "yes"}' | jsonmap "{cat: this.cat}"
{"cat":"yes"}
{"cat":"yes"}

if your code gets too complex and you'd rather use an external file you can also just specify a module to get required:

$ echo '{"foo": "bar"}\n{"baz": "taco"}' | jsonmap --file=transform.js
{"foo":"bar","pizza":1}
{"baz":"taco","pizza":1}

the above will work if transform.js has the following contents:

module.exports = function() {
  this.pizza = 1
}

if you have es6 template strings enabled on your platform (e.g. iojs), template strings will work as well

$ echo '{"meal": "pizza"}\n{"meal": "taco"}' | jsonmap '`i love ${this.meal}`'
"i love pizza"
"i love taco"

if you want to provide a through2 function in a file for more control, or async, you can

$ echo '{"foo": "bar"}\n{"baz": "taco"}' | jsonmap --file=transform.js --through
{"foo":"bar","pizza":1}
{"baz":"taco","pizza":1}

the above will work if transform.js has the following contents:

module.exports = function(obj, enc, next) {
  var self = this;
  if(obj.foo === 'bar') return next() // skip the bar
  process.nextTick(function(){
    self.push({ count: obj.pizza })
    next()
  })
}

you disable JSON parsing (to e.g. process a file line by line as JS strings) by passing jsonmap --no-parse

2.0.1

8 years ago

2.0.0

8 years ago

1.6.3

10 years ago

1.6.2

10 years ago

1.6.1

10 years ago

1.6.0

10 years ago

1.5.0

10 years ago

1.4.0

10 years ago

1.3.0

11 years ago

1.2.0

11 years ago

1.1.2

11 years ago

1.1.1

11 years ago

1.0.0

11 years ago