qw(all);
use JSON;
use Moo;
use MooX::Types::MooseLike::Base qw(:all);
use HTML::Linear::Path::Colors;
## no critic (ProhibitPackageVars)
our $VERSION = '0.019'; # VERSION
has json => (
is => 'ro',
isa => InstanceOf['JSON'],
default => sub { JSON->new->ascii->canonical },
lazy => 1,
);
has address => (is => 'rw', isa => Str, required =
$ref->{attr} = $self->attributes if keys %{$self->attributes};
return $self->key($self->json->encode($ref));
}
sub as_xpath {
my ($self, $strict) = @_;
my $xpath = _wrap(separator
pers::JsonEncoder;
use strict;
use warnings;
use JSON::MaybeXS qw(JSON);
use Moo::Role;
our $VERSION = "0.01";
has _json_encoder => (
is => 'ro',
lazy => 1,
builder => '_build_json_enco
handles => {
encode_json => 'encode',
decode_json => 'decode',
},
);
sub _build_json_encoder { JSON->new->utf8(1); }
sub json_bool { $_[1] ? JSON->true : JSON->false }
1;
__END__
=
ead1 NAME
WebApp::Helpers::JsonEncoder - Simple role for en/decoding JSON
=head1 SYNOPSIS
package MyTunes::Resource::CD;
use Moo;
with 'WebApp::Helpers::JsonEncoder';
has title
Class::Schema::Loader
DB_File
Daemon::Generic
Data::DPath
Data::Float
Data::Printer::Filter::JSON
Data::Printer::Filter::URI
DateTime::Format::ISO8601
DateTime::Format::Strptime
Devel::NYTPro
but then you are responsible for SSL cert verification code...
use LWP::UserAgent 6;
use URI;
use JSON;
use Data::Dumper;
## PUBLIC requests..
use Finance::LocalBitcoins::API::Request::Ticker;
use Fi
->uri . '?' . $uri->query);
}
$request->header(Accept => 'application/json');
# create a new user_agent each time...
$self->user_agent(LWP::UserAge
warn Data::Dumper->Dump([$self->http_response],['Response']) if DEBUG;
$content = $self->json->decode($self->http_response->content);
if (ref $content eq 'ARRAY') {
$self-
ture;
use JSON::PP;
my $g = Data::Random::Structure->new(
max_depth => 2,
max_elements => 5,
);
my $ref = $g->generate();
diag explain $ref;
my $json = JSON::PP->new;
;
use strict;
use constant URL => 'https://localbitcoins.com/bitcoincharts/%s/orderbook.json';
use constant ATTRIBUTES => qw(currency);
use constant REQUEST_TYPE => 'GET';
use constant IS_
);
parameter content_type => (
isa => 'Str',
required => 1,
default => 'application/json',
);
parameter header_exclude => (
isa => 'HashRef',
default => sub {{}},
);
parameter
=> 10,
};
=over
=item content_type
By default the content type is set to "application/json"
=item header_exclude
Acts as a filter, will exclude any header information.
header_exclu
perform a POST request with REST::Consumer::post.
The data will the Content-Type of application/json by default.
=item Other supported HTTP methods
DELETE and PUT: delete(%params) and put(%param
);
parameter content_type => (
isa => 'Str',
required => 1,
default => 'application/json',
);
parameter header_exclude => (
isa => 'HashRef',
default => sub {{}},
);
parameter
=> 10,
};
=over
=item content_type
By default the content type is set to "application/json"
=item header_exclude
Acts as a filter, will exclude any header information.
header_exclu
perform a POST request with REST::Consumer::post.
The data will the Content-Type of application/json by default.
=item Other supported HTTP methods
DELETE and PUT: delete(%params) and put(%param
(-no_match_vars);
use File::Path;
use File::Spec::Functions;
use File::Temp;
use File::chdir;
use JSON;
use Params::Validate qw(:all);
use Scalar::Util qw(weaken);
use URI;
use URI::Escape;
use base
us $status" );
}
);
my %read_req;
%read_req = (
# read one json item at a time
json => sub {
my ( $h, $data ) = @_;
# every successful read resets slee
w, must specify a valid git revision";
}
my $data = $options->{reviewInput};
my $jsondata = encode_json($data);
my $url = join('/',
$options->{http_url},
'a',
'changes',
uri
RACT: A continuum strategy based on a simple "significant bits" static mapping
use JSON::XS qw(encode_json decode_json);
use Array::IntSpan;
use POSIX ();
with 'ShardedKV::Continuum';
has 'num_signi
ncode_json( {
num_significant_bits => $_[0]->num_significant_bits,
from => $_[0]->_original_range_mapping
} )
}
sub deserialize {
my $class = shift;
return $class->new(decode_json( $_[1
Catmandu::Env;
use Catmandu::Sane;
use Catmandu::Util qw(require_package use_lib read_yaml read_json :is :check);
use Catmandu::Fix;
use Config::Onion;
use File::Spec;
use Moo;
require Catmandu;
use
f
grep { -f File::Spec->catfile($path, $_) }
grep /^catmandu.+(?:yaml|yml|json|pl)$/,
readdir $dh;
}
Catmandu->default_load_path;
}
has load_paths => (
as default_importer_package => (is => 'ro', default => sub { 'JSON' });
has default_exporter_package => (is => 'ro', default => sub { 'JSON' });
has store_namespace => (is => 'ro', default => sub { '
ious::Plugin::SessionCompress;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::Util ();
use Mojo::JSON ();
use Compress::Zlib ();
our $VERSION = '0.03';
sub register {
my ($self, $app, $conf) = @_
rialize = delete $conf->{deserialize};
} else {
$serialize = \&Mojo::JSON::encode_json;
$deserialize = \&Mojo::JSON::j;
}
$app->sessions->serialize(sub {
my $hashref = shift;
m
$inflated;
}
=head2 C<serialize>
serialize => \&Mojo::JSON::encode_json
=head2 C<deserialze>
deserialize > \&Mojo::JSON::j
=head2 C<min_size>
min_size minimum size that's allowe
andu::Util qw(data_at);
use Catmandu;
sub description {
<<EOS;
examples:
# export config to JSON
catmandu config
# or any other Catmandu::Exporter
catmandu config to YAML --fix 'delete_field(pas
Catmandu->exporter($into_args->[0], $into_opts);
} else {
$into = Catmandu->exporter('JSON', pretty => 1);
}
$into->add(defined $path ?
data_at($path, Catmandu->config
store
$ echo '{"_id":"001",hello":"world"}' | catmandu import JSON to test
$ echo '{"_id":"001",hello":"world2"}' | catmandu import JSON to test
# In the store we see only the latest version
$ c
[ "verbose|v", "" ],
);
}
sub description {
<<EOS;
examples:
cat books.json | catmandu convert JSON to CSV --fields id,title
options:
EOS
}
sub command {
my ($self, $opts, $args)
Handle::Util ();
use File::Spec;
use YAML::XS ();
use JSON ();
our %EXPORT_TAGS = (
io => [qw(io read_file write_file read_yaml read_json join_path
normalize_path segmented_path)],
# dies on error
YAML::XS::LoadFile($_[0]);
}
sub read_json {
my $text = read_file($_[0]);
# dies on error
JSON::decode_json(read_file($_[0]));
}
sub join_path {
my $path = File:
ng the YAML.
=item read_json($path);
Reads the JSON file at C<$path> into a Perl hash.
my $cfg = read_json($path);
Dies on failure reading the file or parsing the JSON.
=item join_path(@path)
data:
plugins:
- Datestamps
$ echo '{"hello":"world"}' | catmandu import JSON to test
$ catmandu export test to YAML
---
_id: ADA305D8-697D-11E3-B0C3-97AD572FA7E3
date_cre
orter('Foo', file => "/tmp/output.txt");
# Or on the command line
$ catmandu convert JSON to Foo < /tmp/something.txt >/tmp/output.txt
=head1 DESCRIPTION
A Catmandu::Exporter is a Perl
atmandu::Exporter.
=head2 log
Returns the current logger.
=head1 SEE ALSO
L<Catmandu::Addable>, L<Catmandu::Fix>,L<Catmandu::JSON>,
L<Catmandu::YAML>, L<Catmandu::CSV>, L<Catmandu::RIS>
=cut
1;
the root directory of
your programming project. The file can be YAML, JSON or Perl and is called
C<catmandu.yml>, C<catmandu.json> or C<catmandu.pl>. In this file you can set
the default Catmandu sto
gging methods for the
defined log levels, such as C<debug> or C<error>.
package MyApp::View::JSON;
extends 'MyApp::View';
with 'Catmandu::Logger';
sub bar {
$self->log->info
}
Your package automatically has a logging category of MyApp::View::JSON. Use lines like:
log4perl.logger.MyApp::View::JSON=DEBUG,STDOUT
or
log4perl.logger.MyApp::View=DEBUG,STDOUT
or