package App::PipeFilter::Generic::Json;
{
$App::PipeFilter::Generic::Json::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
rint
App::PipeFilter::Role::Input::Json
App::PipeFilter::Role::Output::Json
);
1;
__END__
=pod
=head1 NAME
App::PipeFilter::Generic::Json - a generic JSON pipeline filter
=head1 VERSION
ver
::PipeFilter::JsonCat;
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform::None';
1;
=head1 DESCRIPTION
App::PipeFilter::Generic::Json is a generic
ole::Output::Json;
{
$App::PipeFilter::Role::Output::Json::VERSION = '0.005';
}
use Moose::Role;
use JSON::XS;
sub encode_output {
# Skips $self in $_[0].
return map { encode_json($_) . "\n"
E
App::PipeFilter::Role::Output::Json - serialize output as one JSON object per line
=head1 VERSION
version 0.005
=head1 SYNOPSIS
package App::PipeFilter::JsonToYaml;
use Moose;
extends '
peFilter::Role::Input::Json
App::PipeFilter::Role::Transform::None
App::PipeFilter::Role::Output::Yaml
);
1;
=head1 DESCRIPTION
App::PipeFilter::Role::Output::Json provides an encode_ou
Json;
{
$App::PipeFilter::Role::Input::Json::VERSION = '0.005';
}
use Moose::Role;
use JSON::XS;
has _json => (
is => 'rw',
isa => 'JSON::XS',
lazy => 1,
default => sub { JSON
) = $self->_json()->incr_parse($$buffer_ref);
$$buffer_ref = "";
return @return;
}
1;
__END__
=pod
=head1 NAME
App::PipeFilter::Role::Input::Json - parse input as a stream of JSON records
=h
ic::Json;
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
App::PipeFilter::Role::Input::Json
App::PipeFilter::Role::Output::Json
)
package App::PipeFilter::JsonToYaml;
{
$App::PipeFilter::JsonToYaml::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic';
with (
"App::PipeFilter::Role::Reader::Sysread",
"App::
put::Json",
"App::PipeFilter::Role::Transform::None",
"App::PipeFilter::Role::Output::Yaml",
"App::PipeFilter::Role::Writer::Print",
);
1;
__END__
=pod
=head1 NAME
App::PipeFilter::JsonToYa
f JSON objects into YAML
=head1 VERSION
version 0.005
=head1 SYNOPSIS
Here is the json2yaml(1) pipeline filter.
#!/usr/bin/perl
use App::PipeFilter::JsonToYaml;
exit App::PipeFilter::JsonTo
package App::PipeFilter::MysqlToJson;
{
$App::PipeFilter::MysqlToJson::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::LineByLine
Ap
p::PipeFilter::Role::Output::Json
App::PipeFilter::Role::Transform::None
);
use JSON::XS;
has _fields => (
is => 'rw',
isa => 'ArrayRef',
);
before filter_file => sub {
my ($self, $ifh, $o
ysqlToJson - translate mysql batch output to JSON
=head1 VERSION
version 0.005
=head1 SYNOPSIS
Here is the mysql2json(1) pipeline filter.
#!/usr/bin/perl
use App::PipeFilter::MysqlToJson;
e
::PipeFilter::JsonCut;
{
$App::PipeFilter::JsonCut::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
# TODO - Refactor into a common role? Duplicated in JsonToTsv.pm.
ha
Filter::JsonCut - return specified fields from a JSON stream
=head1 VERSION
version 0.005
=head1 SYNOPSIS
Here is the jcut(1) pipeline filter.
#!/usr/bin/perl
use App::PipeFilter::JsonCut;
exit App::PipeFilter::JsonCut->new_with_options()->run();
=head1 DESCRIPTION
App::PipeFilter::JsonCut implements the jcut(1) pipeline filter. It's
modeled after the UNIX cut(1) utility.
Please see
package App::PipeFilter::JsonPath;
{
$App::PipeFilter::JsonPath::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
use JSON::Path;
has o => (
is => 'rw',
is
[JSON::Path]',
lazy => 1,
default => sub {
my $self = shift;
return [ map { JSON::Path->new($_) } @{$self->o()} ];
},
);
sub transform {
my $self = shift();
my @json
put;
my $c = 0;
foreach my $json_path (@json_paths) {
my $r = 0;
foreach my $json_value ($json_path->values($_[0])) {
$output[$r++]{"col$c"} = $json_value;
}
++$c;
}
re
package App::PipeFilter::JsonIpToUdp;
{
$App::PipeFilter::JsonIpToUdp::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform::IpToUdp';
1
package App::PipeFilter::JsonToPcap;
{
$App::PipeFilter::JsonToPcap::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic';
with (
"App::PipeFilter::Role::Reader::Sysread",
"App::
PipeFilter::Role::Input::Json",
"App::PipeFilter::Role::Transform::None",
"App::PipeFilter::Role::Opener::PcapOutput",
"App::PipeFilter::Role::Output::Pcap",
"App::PipeFilter::Role::Writer::Pca
like JSON rather than whitespace
separated fields.
For example, jcut is a simple version of cut(1) that understands JSON
objects rather than whitespace separated fields.
% head -1 sample.json
{"
node","channel":"#perl","nick":"dngor","karma":"120"}
% jcut -o network -o channel < eg/sample.json | sort | uniq
{"network":"efnet","channel":"#perl"}
{"network":"efnet","channel":"#poe"}
{"
channel":"#reflex"}
The jsonpath filter supports more complex expressions using
JSON::Path's variant of JSONPath.
curl -s 'http://api.duckduckgo.com/?q=poe&o=json' |
jsonpath -o '$..Topics.*.Fir
package App::PipeFilter::JsonEthernetToIp;
{
$App::PipeFilter::JsonEthernetToIp::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform::Et
package App::PipeFilter::JsonMap;
{
$App::PipeFilter::JsonMap::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
has i => (
is => 'rw',
isa => 'Arr
lter::JsonMap - map input fields to output fields by renaming them
=head1 VERSION
version 0.005
=head1 SYNOPSIS
#!/usr/bin/perl
use App::PipeFilter::JsonMap;
exit App::PipeFilter::JsonMap->n
ilter::JsonMap implements the jmap(1) pipeline filter. It
renames JSON object fields by mapping input field names to new ones on
output.
This class subclasses L<App::PipeFilter::Generic::Json>.
=he
::JsonSort;
{
$App::PipeFilter::JsonSort::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
App::PipeFilter::Role::Input::Json
App::PipeFilter::Role::Writer::Print
App::PipeFilter::Role::Transform::None
);
use JSON::XS;
has k => (
is => 'rw',
isa => 'ArrayRef',
default => sub { die "requ
("\t", @sortable{@fields}, encode_json($_)) . "\n";
} @_;
}
1;
__END__
=pod
=head1 NAME
App::PipeFilter::JsonSort - a sort(1)-like filter that understands JSON fields
=head1 VERSION
version 0
pp::PipeFilter::MysqlToJson;
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::LineByLine
App::PipeFilter::Role::Output::Json
App::PipeFilter::
age App::PipeFilter::JsonToYaml;
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
App::PipeFilter::Role::Input::Json
App::PipeFilter:
ic::Json;
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
App::PipeFilter::Role::Input::Json
App::PipeFilter::Role::Output::Json
)
package App::PipeFilter::JsonPcapToEthernet;
{
$App::PipeFilter::JsonPcapToEthernet::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform
kage App::PipeFilter::JsonToTsv;
use Moose;
extends 'App::PipeFilter::Generic';
with qw(
App::PipeFilter::Role::Reader::Sysread
App::PipeFilter::Role::Input::Json
App::PipeFilter:
END__
=pod
=abstract a generic pipeline filter.
=head1 SYNOPSIS
=for example App::PipeFilter::JsonToYaml
=head1 DESCRIPTION
App::PipeFilter::Generic is a generic shell pipeline filter. It is
de
For example, L<App::PipeFilter::JsonToYaml> extends the generic
pipeline filter with a role to read data in large chunks, a role to
parse that input as a stream of JSON objects, a role that doesn't
al
.
This method is usually implemented by Input roles.
=for example App::PipeFilter::Role::Input::Json decode_input
=head2 encode_output ARRAY
encode_output() accepts an array of Perl data structure
package App::PipeFilter::JsonCat;
{
$App::PipeFilter::JsonCat::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform::None';
1;
__END__
peFilter::JsonCat - useless use of cat(1) for JSON streams
=head1 VERSION
version 0.005
=head1 SYNOPSIS
Here is the jcat(1) pipeline filter.
#!/usr/bin/perl
use App::PipeFilter::JsonCat;
ex
it App::PipeFilter::JsonCat->new_with_options()->run();
=head1 DESCRIPTION
App::PipeFilter::JsonCat implements the jcat(1) pipeline filter.
Please see jcat(1) for usage instructions.
This module su