App-JsonLogUtils
view release on metacpan or search on metacpan
#!perl
# ABSTRACT: filters fields in JSON output
# PODNAME: jcut
use strict;
use warnings;
$0 = 'jcut';
use Getopt::Long;
use Pod::Usage;
use JSON::XS qw(encode_json);
use App::JsonLogUtils qw(lines json_cut);
my $help = 0;
my $inverse = 0;
my $fields = '';
GetOptions(
'help' => \$help,
'fields=s' => \$fields,
'complement' => \$inverse,
) or pod2usage(2);
if ($help) {
pod2usage(1);
exit 0;
}
$| = 1;
foreach (@ARGV ? @ARGV : (\*STDIN)) {
my $entries = json_cut $fields, $inverse, lines $_;
while (my $entry = <$entries>) {
print encode_json($entry), "\n";
}
}
exit 0;
__END__
=pod
=encoding UTF-8
=head1 NAME
jcut - filters fields in JSON output
=head1 VERSION
version 0.03
=head1 SYNOPSIS
jcut --field "field1 field2 field3 ..." [--complement] [/path/to/file1 /path/to/file2 ...]
=head1 DESCRIPTION
Outputs JSON objects with only the selected fields from JSON-formatted line
input from supplied file path(s) or standard input if not provided.
=head1 OPTIONS
=head2 --fields | -f
Selects one or more fields to be included in the reformatted JSON output line.
Multiple fields are separated with a space.
=head2 --complement | -c
( run in 0.898 second using v1.01-cache-2.11-cpan-39bf76dae61 )