peConstraints;
use JSON;
subtype 'Bing::Search::Response::Types::JSON'
=> as 'HashRef';
coerce 'Bing::Search::Response::Types::JSON'
=> from 'Str'
=> via { decode_json( $_ ) };
has 'dat
a' => (
is => 'rw',
coerce => 1,
isa => 'Bing::Search::Response::Types::JSON',
trigger => \&_parse
);
with 'Bing::Search::Role::Response::Version';
with 'Bing::Search::Role::Response::Qu
" or "Video" or so forth and so on.
=item C<data>
A hashref, it initially contains the deparsed JSON structure. As objects are
populated, it is depopulated. Anything left over is something Bing se
earch;
use Moose 1.00;
use URI 1.54;
use URI::QueryParam;
use Carp;
use LWP::UserAgent 5.835;
use JSON 2.21;
use Bing::Search::Response;
use vars qw($VERSION);
$VERSION = "0.0005";
$VERSION = eval $V
: $!";
}
my $j = JSON->new->decode( $response->content );
$self->_parse_json( $j );
}
sub _parse_json {
# Debugging!
use Data::Dumper;
my( $self, $json ) = @_;
my $resp = Bin
g::Search::Response->new( data => $json );
$self->response( $resp );
}
sub _make_uri {
my ($self) = @_;
unless( $self->has_sources ) {
croak "No sources means no query, yo.";
}
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::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
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
ackage' => { meta_noindex => 1, } ],
qw(
MetaYAML
MetaJSON
),
[ 'AutoVersion' => { major => $self->major_version, } ],
qw[
README.pod
META.json
]
],
}
],
),
[ 'CopyFilesFromBuild' => {
copy => [qw[ META.json ]],
move => [qw[ .gitignore ]],
}
],
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 Net::Fastly::Client;
use strict;
use warnings;
use JSON::Any;
=head1 NAME
Net::Fastly::Client - communicate with the Fastly HTTP API
=head1 SYNOPSIS
=head1 PROXYING
There are two ways to
my $port = $opts{base_port} ||= 80;
$self->{user} ||= $self->{username};
$self->{_json} = JSON::Any->new;
$self->{_ua} = Net::Fastly::Client::UserAgent->new($base, $port, $opts{pro
self->{password});
die "Unauthorized" unless $res->is_success;
my $content = $self->_json->from_json($res->decoded_content);
$self->{_cookie} = $res->header('set-cookie');
return w
tion::OutputStream;
my $stream_with_options = new AMF::Connection::OutputStream('prefer_number, json_boolean');
$stream->writeInt(1);
$stream->writeLong(1);
# ..
=head1 DESCRIPTION
The AMF
package App::PipeFilter::JsonIpToUdp;
{
$App::PipeFilter::JsonIpToUdp::VERSION = '0.005';
}
use Moose;
extends 'App::PipeFilter::Generic::Json';
with 'App::PipeFilter::Role::Transform::IpToUdp';
1
$stream_with_options = new AMF::Connection::InputStream($binary_buffer_or_string, 'prefer_number, json_boolean');
my $int = $stream->readInt();
my $long = $stream->readLong();
# ..
=head1 DES
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::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
::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::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
文字列でも構いません。オブジェクトの場合は L<JSON::XS> にて JSON encode された結果が戻ります。
JSON::XS が使われるのが嫌な場合には、自前で文字列
rver;
use strict;
use warnings;
use AE;
use Data::Dumper;
use File::ShareDir;
use File::Spec;
use JSON::XS;
use HTTP::Request;
use LWP::UserAgent;
use Path::Class;
use Time::HiRes;
use Plack::App::Di
th, $req, $session);
$res ||= Plack::Response->new( 200, [ 'Content-Type' => 'application/json' ], '{msg:"ok"}' );
} elsif ($apiurl && $req->uri->path =~ /$apiurl/) {
# ajax reque
quest}->{requests} ];
$current->{pop_tap_request}->{cv}->send(
$self->json_response($stack)
);
}
} else {
# ajax request?
my $path =
en => $server->auto_open,
)
);
}
package JSTAPd::Server::Contents::contents;
use JSON::XS ();
sub AUTOLOAD {
my($class, $server, $req, $session, $args) = @_;
my $path = our $
if (ref($ret)) {
return Plack::Response->new(200, [ 'Content-Type' => 'application/json' ], JSON::XS->new->ascii->encode($ret) );
} else {
return Plack::Response->new(200, [ 'Co
e Catalyst::Plugin::Snippets;
use strict;
use warnings;
use MRO::Compat;
BEGIN { eval { require JSON::Syck } }
our $VERSION = "0.03";
sub setup {
my $app = shift;
my $ret = $app->maybe::ne
n",
allow_refs => 1,
use_session_id => 0,
json_content_type => "application/javascript+json",
content_type => "text/plain",
%{ $app->config->{sni
ponse->body($body);
}
sub _send_snippet_json {
my ( $c, $options, $value ) = @_;
$c->_send_snippet(
$options->{json_content_type},
JSON::Syck::Dump($value),
);
}
sub _sen