NAME

jl - Show the "JSON in JSON" Log Nicely

SYNOPSIS

The jl command allows you to recursively decode JSON in JSON string

$ echo '{"foo":"{\"bar\":\"{\\\"baz\\\":123}\"}"}' | jl
{
   "foo" : {
      "bar" : {
         "baz" : 123
      }
   }
}

OPTIONS

x

If you set x option, then JSON values and parsed elements are split as array by [\t\n\r] before/after recursive JSON decoding.

This option is useful for below case:

$ echo '{"message":"[05/09/2019 23:51:51]\t[warn]\t{\"foo\":\"bar\"}"}' | jl -x
{
   "message" : [
      "[05/09/2019 23:51:51]",
      "[warn]",
      {
         "foo" : "bar"
      }
   ]
}

TAB delimited string has been arraynized. It's easy to treat by jq.

xx

If you set xx option, then the elements are split as array by comma after recursive JSON decoding.

This option is useful for below case:

$ echo '{"message":"[05/09/2019 23:51:51] foo, bar, baz \n{\"foo\":\"bar\"}\n"}' | jl -xx
{
   "message" : [
      [
         "[05/09/2019 23:51:51] foo",
         "bar",
         "baz "
      ],
      {
         "foo" : "bar"
      }
   ]
}

xxx

If you set xxx option, then the elements are split as array without delimiter by each parenthesis and brackets (exclude braces {}) after recursive JSON decoding.

This option is useful for below case:

$ echo '{"message":"[05/09/2019 23:51:51](warn)<server> \n{\"foo\":\"bar\"}\n"}' | jl -xxx
{
   "message" : [
      [
         "[05/09/2019 23:51:51]",
         "(warn)",
         "<server>",
         " "
      ],
      {
         "foo" : "bar"
      }
   ]
}

xxxx

If you set xxxx option, then the elements such like a unix timestamp are converted as local date time after recursive JSON decoding.

This option is useful for below case:

$ echo '{"message":"[05/09/2019 23:51:51](warn)<server> \n{\"time\":1560026367123}"}' | jl -xxxx
{
   "message" : [
      [
         "[05/09/2019 23:51:51]",
         "(warn)",
         "<server>",
         " "
      ],
      {
         "time" : "2019-06-09 05:39:27.123"
      }
   ]
}

timestamp-key

You can set custom timestamp-key to convert unix timestamp to date time.

$ echo '{"message":"{\"ts\":1560026367123}"}' | jl --timestamp-key ts
{
   "message" : {
      "ts" : "2019-06-09 05:39:27.123"
   }
}

Supports unixtime 1560026367, msec 1560026367123 and 1560026367.123

xxxxx

If you set xxxxx option, then forcely convert to datetime string from integer value which is over 946684800 (2000-01-01T00:00:00Z).

NOTE that if you set xxxx option, then it means that x, xx and xxx are enabled as well. xxx is going to be enabled x and xx as well. So xx is including x.

X

If you set X (capital X) option, it's a shortcut to work as same as xxxxx option.

gmtime

If you set gmtime flag, then unix timestamp converts date time as GMT instead of localtime.

grep REGEXP

If set grep option with regexp, filtering JSON which is matched regexp.

ignore REGEXP

If set ignore option with regexp, filtering JSON which is unmatched regexp.

no-pretty

If set no-pretty option, then output JSON is not prettify. (default: false, Do prettify)

yaml

If set yaml option, show output string as YAML instead.

unbuffered

If set unbuffered option, flush the output after each line is printed.

stderr

If set stderr option, output line to STDERR instead.

sweep

If set sweep option, filtering non-JSON lines. By default, non-JSON line prints as raw.

NOTE that non-JSON line, a line just consists of [\t\s\r\n] will be filtered.

AUTHOR

Dai Okabayashi <bayashi@cpan.org>

SEE ALSO

App::jl

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.