Skip to content

tizzo/json-stream-formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Event Stream Formatter

Build Status Coverage Status

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

About

A command line tool and through stream for formatting streams of JSON objects into a text stream.

Resources

Stars

Watchers

Forks

Packages

No packages published