/*
* JSON Parser
*
* Copyright IBM, Corp. 2009
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
* See
QEMU_JSON_PARSER_H
#define QEMU_JSON_PARSER_H
#include "qemu-common.h"
#include "qapi/qmp/qlist.h"
#include "qapi/error.h"
QObject *json_parser_parse(QList *tokens, va_list *ap);
QObject *json_pars
ct;
use warnings;
use Carp;
use Groonga::API;
use Groonga::API::Constants qw/GRN_CTX_USE_QL/;
use JSON::XS ();
no bytes;
use constant DEFAULT_PORT => 10041;
our $VERSION = $Groonga::API::VERSION;
s
x, $host, $port, 0);
croak "failed to connect to $host:$port ($rc)" if $rc;
}
$args{_json} = JSON::XS->new->utf8($args{encoding} ? 1 : 0);
bless \%args, $class;
}
sub do {
my ($self, @a
($self->{encoding}) {
$res = Encode::decode($self->{encoding}, $res);
}
eval { $self->{_json}->decode($res) } || $res;
}
sub ctx { shift->{_ctx} }
sub db { shift->{_db} }
sub DESTROY {
ERSION = '1.140440';
}
# ABSTRACT: Interface to http://www.omdbapi.com/
use LWP::UserAgent;
use JSON;
use constant BASE_URL => 'http://www.omdbapi.com/';
sub search {
my ( $s, $options ) = @_;
nse = _get( 's', $s, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content->{Search};
}
else {
die $response-
nse = _get( 'i', $i, $options );
if ( $response->is_success ) {
my $content = decode_json( $response->content );
return $content;
}
else {
die $response->status_li
83357'],
['Plack::Middleware::AxsLog' => '== 0.20', 'Missing \n'],
);
our @XS = (
['JSON' => 'JSON::XS'],
# ['PPI' => 'PPI::XS'], # I think PPI::XS is outdated.
['Plack' => 'HTTP::Par
S, ['Filesys::Notify::Simple', 'Linux::Inotify2'];
}
our @FEATURE = (
['Amon2' => '< 3.29', 'JSON hijacking detection.'],
['Log::Minimal' => '< 0.10', 'LM_COLOR'],
['Log::Minimal' => '< 0
/*
* QObject JSON integration
*
* Copyright IBM, Corp. 2009
*
* Authors:
* Anthony Liguori <aliguori@us.ibm.com>
*
* This work is licensed under the terms of the GNU LGPL, version 2.1 or la
ry.
*
*/
#ifndef QJSON_H
#define QJSON_H
#include <stdarg.h>
#include "qemu/compiler.h"
#include "qapi/qmp/qobject.h"
#include "qapi/qmp/qstring.h"
QObject *qobject_from_json(const char *string)
QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2);
QObject *qobject_from_jsonv(const char *string, va_list *ap) GCC_FMT_ATTR(1, 0);
QString *qobject_to_json(const QObject *obj);
as defined in L<http://www.mongodb.org/display/DOCS/Database+References>,
for example (this is a JSON example):
{ "$ref": "collection_name", "$id": ObjectId("4cbca90d3a41e35916720100") }
=cut
wit
command will POST to MYREDMINE_SERVER/time_entries.json
#{time_entry => {issue_id => 3, activity_id => 9, hours => 1, comments => 'test'}} in JSON format
$c->time_entries->time_entry->create(i
nicate with Redmine thought the REST::Api.
Any result will be a perl HASH, transformation of the json response into a perl HASH.
=head1 NOTES
The Redmine API is not fully complete, and you should u
warnings-are-a-ticking-time-bomb.html
use warnings NONFATAL => 'all';
use Carp ();
use URI;
use JSON;
use HTTP::Headers;
use LWP::UserAgent;
use LWP::Protocol::https;
use URI::QueryParam;
has 'api_
', is => 'ro', default => sub { 'https://www.dogeapi.com/wow/' };
has 'json', is => 'ro', default => sub {
my $j = JSON->new; $j->allow_nonref; $j
};
has 'ua', is => 'ro', default =>
sub {
my $headers = HTTP::Headers->new;
$headers->header( 'Content-Type' => 'application/json' );
LWP::UserAgent->new(
ssl_opts => { verify_hostname => 1 },
default_
package WWW::NHKProgram::API::Provider::Genre;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Genre qw/fetch_genre_id
:Provider::Common::call(
$context,
"genre/%(area)s/%(service)s/%(genre)s/%(date)s.json",
{
area => $area,
service => $service,
genre =>
$genre,
date => $date,
},
$raw,
);
return $content if $raw;
return JSON::decode_json($content)->{list}->{$service};
}
1;
package WWW::NHKProgram::API::Provider::Common;
use strict;
use warnings;
use utf8;
use Carp;
use JSON ();
use Text::Sprintf::Named qw/named_sprintf/;
use constant API_ENDPOINT => "http://api.nhk.or.
ess) {
if ($raw) {
croak $res->{content};
}
my $fault = JSON::decode_json($res->{content})->{fault};
my $fault_str = $fault->{faultstring};
my $faul
package WWW::NHKProgram::API::Provider::List;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Service qw/fetch_service_i
.json",
{
area => $area,
service => $service,
date => $date,
},
$raw,
);
return $content if $raw;
return JSON::decode_json
$client->genre_raw()
=item * $client->info_raw()
=item * $client->now_on_air_raw()
Returns raw JSON response of each API.
=back
=head1 FOR DEVELOPERS
Tests which are calling web API directly in
n, and will simply reference the novel with a
'novel' attribute.
=back
Let's look at a possible JSON representation of a novel - "The Valley of
Fear" by Sir Arthur Conan Doyle:
# in the 'novels' c
atabase (as described in L<MongoDBx::Class/"CAVEATS AND THINGS TO CONSIDER">).
So, looking at the JSON representations from before, we need to modify
the representations like so:
# in the 'novels' c
to the API
use strict;
use warnings;
our $VERSION = '0.04'; # VERSION
use Moo;
use Carp;
use JSON;
use REST::Client;
has 'request' => (
is => 'ro',
isa => sub {
croak "request s
_key );
$cli->addHeader( 'Content-Type' => 'application/json' );
$cli->addHeader( 'Accept' => 'application/json' );
return $cli;
}
sub create {
my ( $self, %data ) =
esponse(
$self->_rest_cli->POST(
'/' . $self->request->route . '.json',
encode_json( { $self->action => \%data } ),
)
);
}
sub all {
my ( $self, %optio
package WWW::NHKProgram::API::Provider::Now;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Service qw/fetch_service_id
a)s/%(service)s.json",
{
area => $area,
service => $service,
},
$raw,
);
return $content if $raw;
return JSON::decode_json($content)->{no
strict;
use utf8;
use warnings;
use warnings qw(FATAL utf8); # Fatalize encoding glitches.
use JSON::XS;
use Try::Tiny;
# We don't use Moo because we isa CGI::Snapp.
our $VERSION = '2.04';
# --
hes: " . scalar @$response);
# Warning: Do not use ... new -> utf8 -> encode...
$response = JSON::XS -> new -> encode($response);
$self -> param('db') -> simple -> commit;
}
catch
{
my($
log the error despite the error.
$self -> log(error => "System error: $error");
$response = JSON::XS -> new -> encode([$self -> param('system_error')]);
};
return $response;
} # End of displ
=> 1, # include results
t => 'XML', # or JSON
u => 'http://yourdomain.foo/opensearch/',
b => 'AND', #
package WWW::NHKProgram::API::Provider::Info;
use strict;
use warnings;
use utf8;
use JSON ();
use WWW::NHKProgram::API::Area qw/fetch_area_id/;
use WWW::NHKProgram::API::Service qw/fetch_service_i
s.json",
{
area => $area,
service => $service,
id => $id,
},
$raw,
);
return $content if $raw;
return JSON::decode_json(
use JSON::XS;
use Web::Query;
use WebService::SyoboiCalendar::Error;
use WebService::SyoboiCalendar::API::Search;
Readonly my $API_RSS2 => "http://cal.syoboi.jp/rss2.php";
Readonly my $API_JSON =>
"http://cal.syoboi.jp/json.php";
Readonly my $API_LOGIN => "http://cal.syoboi.jp/usr";
has ua => (
is => 'ro',
default => sub {
my $ua = LWP::UserAgent->new;
$ua->cookie_jar
s->is_error;
$res;
}
sub get_json {
my ($self, $url, $args) = @_;
my $res = $self->get($url, $args);
my $json = decode_json($res->content);
$json;
}
sub _param {
args_pos my
se case, however, the output was needed in
JSON format, not HTML. One solution would have been to use the text-based
templating system to produce a valid JSON document (quite risky). The other solutio
in code, and use a JSON serializer on that, bypassing the template
output.
The third solution would have been to provide a template that did not directly
produce the serialised JSON text, but describ
orking only with structured data, and never with text,
the serialized output must always be valid JSON.
This (minus the serialization) is the domain of C<Positron::DataTemplate>.
=head1 EXAMPLES
Th