json-stream-formatter
v0.0.9
Published
A command line tool and through stream for formatting streams of JSON objects into a text stream.
Downloads
60
Readme
JSON Event Stream Formatter
Usage
CLI usage
By default json-stream-format pretty prints a json stream. If you want to use a more specific format you can use the
--format
(-f
) parameter and specify the format. Place object keys to include inside double curly {{something}}
brackets.
Example
cat test/fixtures/example.log | json-stream-format --format '{{time|date("h:m:s")|blue}}: {{msg|green}}'
You can also leave off the format, non-parameter arguments will be used as formats by default.
cat test/fixtures/example.log | json-stream-format '{{time|date("h:m:s")|blue}}: {{msg|green}}'
Node.js usage
Formatting
var jsf = require('json-stream-formatter');
var es = require('event-stream');
process.stdin
.pipe(es.split())
.pipe(es.parse())
.pipe(jsf.format('{{time|date("d/m/y h:m:s")|blue}}: {{msg}}'))
.pipe(process.stdout);
Pretty printing
var jsf = require('json-stream-formatter');
var es = require('event-stream');
process.stdin
.pipe(es.split())
.pipe(es.parse())
.pipe(jsf.prettyPrint())
.pipe(process.stdout);
Format sytnax
The formatter utilizes twig.js for foratting the json event messages. Available filters can be found in the twig.js implementation notes. In addition chalk-twig-filters are added to provide all of the chalk colors as twig filters. These are the color filters used in the examples above.
Installation
sudo npm install -g json-stream-formatter