he current package, we then get to use the overload code
on stringification AND Mojo::JSON gets to use the TO_JSON method when
converting this into something to be transported to the frontend.
=cut
ine $line";
}
"$_"
} @args];
}
=head2 $str->TO_JSON
Help L<Mojo::JSON> encode us into JSON.
=cut
sub TO_JSON ($self) {
my $ret = $#$self == 0 ? $self->[0] : [@$self];
r
use strict;
use warnings;
use Test::More;
use JQ::Lite;
my $json = q({
"users": [
{
"name": "Alice",
"friends": [ { "name": "Charlie" }, { "name": "Dave" } ]
},
{
"nam
iends": [ { "name": "Eve" } ]
}
]
});
my $jq = JQ::Lite->new;
my @result = $jq->run_query($json, ".users[].friends[].name");
is_deeply(\@result, ['Charlie', 'Dave', 'Eve'], 'Multi-level array
);
my $result = $search->query_tree();
say $result->qtree;
$result->move_to( 'qtree.json' );
=head1 DESCRIPTION
The QTree class holds the
L<response|https://ui.adsabs.harvard.edu/help/
#----------------------------------------------------------------------------
## JSON Schema Validator - ~/lib/App/jsonvalidate.pm
## Version v0.1.0
## Copyright(c) 2025 DEGUEST Pte. Ltd.
## Author: J
self.
##----------------------------------------------------------------------------
package App::jsonvalidate;
use strict;
use warnings;
use vars qw( $VERSION );
our $VERSION = 'v0.1.0';
sub init
{
__END__
=encoding utf-8
=head1 NAME
App::jsonvalidate - App harness for the jsonvalidate CLI
=head1 SYNOPSIS
Run C<jsonvalidate -h> or C<perldoc jsonvalidate> for more options.
=head1 VERSION
es->code,message=>$res->message,body=>($res->body//''))->throw if $res->is_error;
my $j = $res->json; $token = $j->{access_token}; $refresh = $j->{refresh_token}//$refresh; $expires_at = time + ($j-
es->code,message=>$res->message,body=>($res->body//''))->throw if $res->is_error;
my $j = $res->json; $token = $j->{access_token}; $refresh = $j->{refresh_token}//$refresh; $expires_at = time + ($j-
package CallBackery::Model::ConfigJsonSchema;
=head1 NAME
CallBackery::Model::ConfigJsonSchema - get parse configuration file for CallBackery
=head1 SYNOPSIS
use CallBackery::Model::ConfigYAML;
:Config', -signatures;
use JSON::Validator;
use Mojo::Exception;
use Mojo::Util qw(dumper);
use Mojo::Loader qw(data_section);
use YAML::XS qw(LoadFile Load);
use Mojo::JSON qw(true false);
use CallBa
ckery::Translate qw(trm);
$YAML::XS::Boolean = 'JSON::PP';
=head2 cfgHash
a hash containing the data from the config file
=cut
my $walker;
$walker = sub ($data, $cb, $path='' ) {
if (ref $dat
ie;
use File::Spec;
use Locale::PO;
use Mojo::Promise;
use Mojo::Loader qw(load_class);
use Mojo::JSON qw(true false);
use Mojo::Exception;
use Scalar::Util qw(blessed);
# use Devel::Cycle;
=head2 fi
@base64 encodes objects via JSON representation');
my @array = $jq->run_query('["a","b"]', '@base64');
is_deeply(\@array, ['WyJhIiwiYiJd'], '@base64 encodes arrays via JSON representation');
done_te
ore;
use JQ::Lite;
my $json = q({
"users": [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Carol", "age": 35}
],
"tags": ["perl", "json", "cli"],
"title": "j
,
"flags": [true, false, true]
});
my $jq = JQ::Lite->new;
my @object_index = $jq->run_query($json, '.users | index({"name":"Bob","age":25})');
is(scalar @object_index, 1, 'object index returns si
ray_index = $jq->run_query($json, '.tags | index("perl")');
is($array_index[0], 0, 'scalar array search returns zero-based index');
my @string_index = $jq->run_query($json, '.title | index("lite")');
tests => 3;
use JSON::PP;
use JQ::Lite;
my $jq = JQ::Lite->new;
# --- 1. Existing value should not be replaced
my $json1 = '{"nickname":"alice"}';
my @result1 = $jq->run_query($json1, '.nickname |
override existing value');
# --- 2. Undefined value should be replaced
my $json2 = '{}';
my @result2 = $jq->run_query($json2, '.nickname | default("unknown")');
is($result2[0], 'unknown', 'default()
ult for missing field');
# --- 3. Null value should be replaced
my $json3 = '{"nickname":null}';
my @result3 = $jq->run_query($json3, '.nickname | default("unknown")');
is($result3[0], 'unknown', 'de
ings;
use Test::More;
use JSON::PP;
use JQ::Lite;
my $json = <<'JSON';
{
"object": {
"third": 3,
"first": 1,
"second": 2
},
"array": ["a", "b", "c"]
}
JSON
my $jq = JQ::Lite->new;
# --- objects ---
my @object = $jq->run_query($json, '.object | keys_unsorted');
my @sorted = $jq->run_query($json, '.object | keys');
# Set equality: keys_unsorted (when sorted) should equal keys
i
= $jq->run_query($json, '.array | keys_unsorted');
is_deeply($array[0], [0, 1, 2], 'keys_unsorted returns indexes for arrays');
# --- scalars ---
my @scalar = $jq->run_query($json, '.array[0] | keys
:More;
use JQ::Lite;
my $json = <<'JSON';
[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
JSON
my $jq = JQ::Lite->new;
my @results = $jq->run_query($json, '.[] | {"name": .name}'
],
'object constructor builds hashes with selected fields',
);
@results = $jq->run_query($json, '.[] | {name: .nickname}');
is_deeply(
\@results,
[
{ name => undef },
ng values are represented as null entries in constructed objects',
);
@results = $jq->run_query($json, '.[] | {}');
is_deeply(
\@results,
[ {}, {} ],
'empty object constructors yield emp
n::Qooxdoo::JsonRpcController),
-signatures,-async_await;
use CallBackery::Exception qw(mkerror);
use CallBackery::Translate qw(trm);
use Mojo::JSON qw(encode_json decode_json from_json);
use Synt
$self->tx->remote_address;
$self->log->debug("[$userId|$remoteAddr] CALL $method(".encode_json($data).")");
}
else {
$self->SUPER::logRpcCall(@_);
}
}
=head2 logRpcReturn
ddr = $self->tx->remote_address;
$self->log->debug("[$userId|$remoteAddr] RETURN ".encode_json($data).")");
}
else {
$self->SUPER::logRpcReturn(@_);
}
}
=head2 ping()
ch
ided as JSON command line arguments
=pod
=head1 NAME
Run::WeeklyChallenge - facilitates running a solution to https://theweeklychallenge.org using one or more sets of inputs provided as JSON comman
# are given
my $inputs_example = '{"ints":[1,2,3]}';
# jsonschema (draft2020-12) for a set of inputs
my $inputs_schema_json = '{
"type": "object",
"properties": {
ma_json);
Example output:
$ perl example.pl '{"ints":[1,2,3]}' '{"ints":[]}'
Inputs: {"ints":[1,2,3]}
Output: 6
Inputs: {"ints":[]}
Output: 0
You must provide an example JSON in
PERL_MB_OPT})] : [];
$self->{configure_args} = [@_];
$self->meta->save(@$_) for ['MYMETA.json'], [ 'MYMETA.yml' => { version => 1.4 } ];
}
1;
=head1 COPYRIGHT AND LICENSE
This software is
use strict;
use warnings;
use Test::More;
use JQ::Lite;
my $json = q({
"price": 19.2,
"discount": 1.5,
"debt": -1.7,
"tiny": -0.2,
"numbers": [1.49, 1.5, -1.49, -1.5, "n/a", null, [2.6, -2.
@round_price = $jq->run_query($json, '.price | round');
is($round_price[0], 19, 'round rounds positive scalar down when < .5');
my @round_discount = $jq->run_query($json, '.discount | round');
is($ro
nd_debt = $jq->run_query($json, '.debt | round');
is($round_debt[0], -2, 'round rounds negative scalar away from zero when beyond -.5');
my @round_tiny = $jq->run_query($json, '.tiny | round');
is($r
t()->then(sub ($result){
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub ($err) {
$self->render(json => { 'result' => 0, data => $err });
});
@next_results = ();
for my $item (@results) {
my $json = JQ::Lite::Util::_encode_json($item);
for my $segment (@sequence_parts) {
}
}
my @outputs = $self->run_query($json, $filter);
push @next_results, @outputs;
}
}
t;
}
my $json = JQ::Lite::Util::_encode_json($item);
my @outputs = $self->run_query($json, $element);
if (@outputs) {
trict; # do we want -signatures
use Mojo::DOM;
use Mojo::File qw( path );
use Mojo::JSON qw( decode_json encode_json );
use Mojo::URL;
use Mojo::Util qw( quote url_escape );
use PerlX::Maybe;
use Type
};
return Astro::ADS::Result->new( {error => $error_obj} );
}
return $response->json;
}
sub fetch {
my ($self, $bibcode) = @_;
$bibcode ||= $self->bibcode()
or die
se_url->clone->path($path);
my $response = $self->get_response( $url );
return $response->json;
}
sub batch {
my ($self, $bibcodes, $options) = @_;
my $url = $self->base_url->clone->p
p()->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { result => 0, data => $err });
})->wai
ey)->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { result => 0, data => $err });
})->wai