package Plack::Middleware::JSONParser;
use strict;
use warnings;
use JSON;
use Hash::MultiValue;
use Plack::Request;
our $VERSION = "0.02";
use parent 'Plack::Middleware';
sub call {
my ($self,
m{\Aapplication/json}o) {
my $req = Plack::Request->new( $env );
my $raw_body = $req->raw_body();
return $self->app->($env) unless ($raw_body);
my $json;
{
local $@;
$json = eval { decode_json($raw_body) };
if ($@) {
die $@ if $self->{die_when_failed};
$env->{'plack.middleware.jsonparser.error'} = $@;
$self = shift;
require JSON;
my $uri = Opsview::REST::Config->new(
$obj_type,
json_filter => JSON::encode_json({@_}),
);
DESCRIPTION
The default typemap is actually defined per backend, in
L<KiokuDB::TypeMap::Default::JSON> and L<KiokuDB::TypeMap::Default::Storable>.
The list of classes handled by both is the same, but
ethod;
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use Encode;
use JSON;
our $VERSION = '0.7';
my $SERVICE_TYPE = "rest";
my $API_VERSION = "0.0";
my $UA_SUFFIX = "Pe
shift;
my %params = @_;
my %merged_params = ( 'method' => $self->{METHOD},
'format' => 'json',
'api_key' => $self->{APIKEY},
%params );
my $response = $self->{ua}->request(POST $se
->is_success) {
$self->{error} = $response->status_line;
return undef;
}
my $result = from_json($response->content);
if ($result->{status} ne 'ok') {
$self->{error} = "method returned " . $
a associated with it.
Since the default serializer for the DBI backend is
L<KiokuDB::Serializer::JSON>, we examine the data.
First let's set C<sqlite>'s output mode to C<line>. This is easier to rea
"id":"05A8D61C-6139-4F51-A748-101010CC8B02","root":true}
You'll notice the C<spouse> field has a JSON object with a C<$ref> field inside
it holding the UUID of the target object.
When data is loaded
use Carp 'croak';
use Dancer ':syntax';
use Dancer::Plugin;
my $content_types = {
json => 'application/json',
yml => 'text/x-yaml',
xml => 'application/xml',
};
our $default_serialize
(
($conf && exists $conf->{serializers})
? $conf->{serializers}
: { 'json' => 'JSON',
'yml' => 'YAML',
'xml' => 'XML',
'dump' => 'Dumper',
format' => sub {
User->find(params->{id});
};
# curl http://mywebservice/user/42.json
{ "id": 42, "name": "John Foo", email: "john.foo@example.com"}
# curl http://mywebservic
use Form::Toolkit::Clerk::Hash;
use Form::Toolkit::Field;
use Form::Toolkit::Field::String;
use JSON;
use MIME::Base64;
use Scalar::Util;
with qw(MooseX::Clone);
=head1 NAME
Form::Toolkit::Form
for Form implementation
=cut
__PACKAGE__->meta->id_prefix('form_');
has 'jsoner' => ( isa => 'JSON' , is => 'ro', required => 1, lazy_build => 1);
has 'fields' => ( isa => 'ArrayRef[Form::Toolkit
lds
=cut
sub BUILD{
my ($self) = @_;
$self->build_fields();
}
sub _build_jsoner{
my ($self) = @_;
return JSON->new->ascii(1)->pretty(0);
}
=head2 fast_clone
Returns fast clone of this fo
ojolicious::Plugin::DirectoryQueue;
use Mojo::Base 'Mojolicious::Plugin';
use Mojo::JSON qw(decode_json encode_json);
use Directory::Queue;
use POSIX qw(chown);
our $VERSION = '0.01';
sub register
elper(
enqueue => sub {
my ($self, $args) = @_;
$dirq->add(encode_json($args));
},
);
$app->helper(
dequeue => sub {
for (my $name
my $data = $dirq->get($name);
$dirq->remove($name);
return decode_json($data) if $data;
}
return;
},
);
$app->helper(
s
rom_stream";
my %types = (
storable => "KiokuDB::Serializer::Storable",
json => "KiokuDB::Serializer::JSON",
yaml => "KiokuDB::Serializer::YAML",
);
coerce( __PACKAGE__,
from
ta structure modeling this object/reference. This is a tree, not
a graph, and has no shared data (JSON compliant). All references are symbolic,
using a L<KiokuDB::Reference> object with UIDs as the
ad
okenized JSON
Using modules:
=over
=item *
L<Pistachio::Language>
=item *
L<https://github.com/joeldalley/lib-JBD> (JBD::JSON).
=back
In this example, JBD::JSON is used to parse JSON text int
n types JBD::JSON produces to CSS definitions.
use strict;
use warnings;
use Pistachio;
use Pistachio::Token;
use Pistachio::Language;
use JBD::JSON 'std_parse';
# Argument: JSON input text.
Returns arrayref of Pistachio::Tokens.
my $tokens = sub {
my $tokens = std_parse 'json_text', $_[0];
[map Pistachio::Token->new($_->type, $_->value), @$tokens];
};
# Argument: a token t
eserialize);
my %types = (
storable => "KiokuDB::Serializer::Storable",
json => "KiokuDB::Serializer::JSON",
yaml => "KiokuDB::Serializer::YAML",
memory => "KiokuDB::Seriali
nd::Serialize::Storable>,
L<KiokuDB::Backend::Serialize::YAML> and L<KiokuDB::Backend::Serialize::JSON>
for examples.
=head1 REQUIRED METHODS
=over 4
=item serializate $entry
Takes a L<KiokuDB::En
rk;
{
$Form::Toolkit::Clerk::VERSION = '0.008';
}
use Moose;
use DateTime::Format::ISO8601;
use JSON;
has 'source' => ( required => 1 , is => 'ro' );
has '_date_parser' => ( is => 'ro' , default =
ouchdb" => "CouchDB",
"mongodb" => "MongoDB",
);
sub _try_json {
my $json = shift;
require JSON;
JSON->new->decode($json);
}
sub dsn_to_backend {
my ( $dsn, @args ) = @_;
i
d_class($class);
return $class->new_from_dsn($rest, @args);
} elsif ( my $args = _try_json($dsn) ) {
my $dsn;
if ( ref $args eq 'ARRAY' ) {
( $dsn, $args ) = @
TP::Request::Common qw(GET POST);
use URI;
use URI::QueryParam;
use LWP::UserAgent;
use JSON qw(to_json from_json);
use Carp qw(croak);
use Log::Any qw($log);
use Try::Tiny;
has scheme => (is => 'ro
(
q => $query,
format => 'json',
env => 'store://datatables.org/alltableswithkeys',
jsonCompat => 'new',
);
my $uri = URI->new($self->u
$res = $self->ua->request($req);
}
return from_json $res->content
if $res->code =~ /^4/x;
return $res->content ? from_json($res->content)->{query}{results} : 1;
}
sub _log_conte
a simplified representation of the object, allowing the data to be
saved in formats as simple as JSON.
References to other objects are converted to symbolic references in the entry,
so objects can b
to pass it in:
KiokuDB->connect( $dsn, typemap => $typemap );
The DSN can also be a valid L<JSON> string taking one of the following forms:
dsn => '["dbi:SQLite:foo",{"schema":"MyApp::DB"}]
otion;
use 5.008005;
use strict;
use warnings;
use AnyEvent::Handle;
use AnyEvent::Socket ();
use JSON ();
use Protocol::WebSocket;
use Protocol::WebSocket::Frame;
use Protocol::WebSocket::Handshake::
if (my $message = $self->{frame}->next_bytes) {
my $data = JSON::decode_json($message);
if (exists $data->{id} && exists $data->{timestamp}) {
});
});
};
}
sub send {
my ($self, $data) = @_;
my $message = JSON::encode_json($data);
my $frame = Protocol::WebSocket::Frame->new($message);
$self->{handle}->pu
l or as URL
'-dataformat' => 'nexus',
'-treeformat' => 'newick',
'-metaformat' => 'json',
'-charsetformat' => 'nexus',
);
my $merger = Bio::BioVeL::Service::NeXMLMerger->new;
my $
package Net::DNSbed;
use 5.006;
use warnings;
use strict;
use Carp qw/croak/;
use JSON;
use LWP::UserAgent;
use vars qw/$VERSION/;
$VERSION = '0.02';
sub new {
my $class = shift;
my $uid =
form-urlencoded');
$req->content($args);
my $res = $ua->request($req);
return decode_json($res->decoded_content);
}
1;
=head1 NAME
Net::DNSbed - Perl client for DNSbed API
=head1 VE
See also L<Coro>.
=back
=head2 JSON
=over 4
=item L<JSON::XS>
JSON::XS is pretty fast. I'm use this for the point what needs performance.
=item L<JSON::PP>
JSON::PP is written in pure perl. And