use strict;
use warnings;
use Test::More;
use JSON::PP;
use JQ::Lite;
my $json = <<'JSON';
{
"items": [
{ "name": "Widget", "value": 1 },
{ "value": 2, "active": true },
{ "nested": { "
],
"single": { "foo": "bar" },
"no_hashes": ["alpha", "beta"]
}
JSON
my $jq = JQ::Lite->new;
my @merged = $jq->run_query($json, '.items | merge_objects');
is_deeply(
\@merged,
[
e => JSON::PP::true,
nested => { id => 42 },
}
],
'merge_objects folds arrays of objects into one hash with later values winning',
);
my @single = $jq->run_query($json, '.
pkey)->then(sub($result) {
$self->render(json => { data => $result->{data}, result => 1 });
})->catch(sub($err) {
$self->render(json => { result => 0, data => $err });
})->wait
ey)->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { result => 0, data => $err });
})->wai
$json = <<'JSON';
{
"items": [
"text",
42,
true,
null,
{"note": "object"},
[1, 2, 3]
],
"flag": false
}
JSON
my $jq = JQ::Lite->new;
my @results = $jq->run_query($json,
;
isa_ok($results[2], 'JSON::PP::Boolean', 'scalars preserves boolean objects');
ok(!defined $results[3], 'scalars keeps null values as undef');
@results = $jq->run_query($json, '.items | scalars');
alars yields no output for array containers');
@results = $jq->run_query($json, '.flag | scalars');
isa_ok($results[0], 'JSON::PP::Boolean', 'scalars passes through scalar booleans');
ok(!$results[0]
Q::Lite;
my $json = q({
"nums": [1, 9, 3, 2],
"words": ["apple", "pear", "banana"],
"mixed": ["10", "2", "30"]
});
my $jq = JQ::Lite->new;
my @desc_nums = $jq->run_query($json, '.nums | sor
t_desc');
my @desc_words = $jq->run_query($json, '.words | sort_desc');
my @desc_mixed = $jq->run_query($json, '.mixed | sort_desc');
is_deeply($desc_nums[0], [9, 3, 2, 1], 'numeric sort descendin
has 'fields' => "document_builder_pkey, editnum, insby, insdatetime, modby, moddatetime, document_json, status";
has 'primary_key_name' => "document_builder_pkey";
has 'table_name' => "document_builde
ey)->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { 'result' => 0, data => $err });
})->w
p()->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { 'result' => 0, data => $err });
})->w
package Net::EANSearch;
use strict;
use warnings;
use LWP;
use JSON;
use URL::Encode;
use MIME::Base64 qw(decode_base64);
require Exporter;
our @ISA = qw(Exporter);
# Items to export into callers
19;
our $BULGARIAN = 20;
our $GREEK = 21;
my $BASE_URI = 'https://api.ean-search.org/api?format=json&token=';
my $MAX_API_TRIES = 3; # retry, eg. on 429 error
sub new {
my $class = shift;
my $tok
my $lang = shift || 1;
my $json_str = $self->_apiCall($self->{base_uri} . "&op=barcode-lookup&ean=$ean&language=$lang");
my $json = decode_json($json_str);
return $json->[0];
}
sub isbnLookup {
t-4.1', temp => '0.0', max => 3000, sub => \&gpty,
prompt => <<END
Translate the following JSON array into %s.
For each input array element, output only the corresponding translated element at
pond to input element n.
Output only the translated elements or unchanged tags/blank strings as a JSON array.
Do not leave any unnecessary spaces or tabs at the end of any array element in your output
ult as a JSON array and nothing else.
Your entire output must be valid JSON.
Do not include any explanations, code blocks, or text outside of the JSON array.
If you cannot produce a valid JSON array,
p()->then(sub($result) {
$self->render(json => { data => $result->{data}, result => => 1 });
})->catch(sub($err) {
$self->render(json => { result => 0, data => $err });
})->wai
);
=head1 HISTORY
See C<Changes> file
=head1 TO DO
See C<TODO> file
=head1 SEE ALSO
L<Mojo::JSON::Pointer>
=head1 AUTHOR
Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cp
->new;
my $simple_json = '{"a":1,"b":2}';
my @simple = $jq->run_query($simple_json, '.a, .b');
is_deeply(\@simple, [1, 2], 'comma emits multiple top-level values');
my $users_json = '[{"name":"Alice
query($users_json, '.[] | (.name, .age)');
is_deeply(\@flat, ['Alice', 30, 'Bob', 25], 'comma branches run against identical inputs in pipelines');
my @arrays = $jq->run_query($users_json, '.[] | [.n
],
'comma preserves evaluation order for each input');
my @prefixed = $jq->run_query($users_json, '(["name","age"]), (.[] | [.name, .age])');
is_deeply(
\@prefixed,
[
['name', 'a
gs;
use Test::More;
use JQ::Lite;
my $json = q({
"number": -10,
"numbers": [-3, 4, -5, "n/a"]
});
my $jq = JQ::Lite->new;
my @scalar = $jq->run_query($json, '.number | abs');
is($scalar[0], 10,
'abs converts scalar numbers to absolute value');
my @array = $jq->run_query($json, '.numbers | abs');
is_deeply(
$array[0],
[3, 4, 5, 'n/a'],
'abs converts numeric array entries and lea
::Lite->new;
sub run_query {
my ($json, $query) = @_;
return [ $jq->run_query($json, $query) ];
}
subtest 'pick on single object' => sub {
my $json = '{"name":"Alice","age":30,"city":
"Paris"}';
my $results = run_query($json, 'pick("name", "age")');
is_deeply(
$results->[0],
{ name => 'Alice', age => 30 },
'returns subset of keys'
);
};
subtest
ay of objects' => sub {
my $json = '{"users":[{"name":"Alice","age":30,"email":"alice@example.com"},{"name":"Bob","age":27}]}';
my $results = run_query($json, '.users | pick("name", "email"
Custom Tools Support
GPT-5 supports custom tools that can receive plaintext payloads instead
of JSON, enabling more flexible integration with external systems.
=head3 Context-Free Grammar (CFG)
Al
<App::Greple::xlate>
=item * L<App::cdif::Command> - For gpty command execution
=item * L<JSON> - For JSON array processing
=back
=head1 SEE ALSO
=over 4
=item * L<App::Greple::xlate>
=item * L
verbosity => 'low', max_completion_tokens => 4000,
prompt => <<END
Translate the following JSON array into %s.
For each input array element, output only the corresponding translated element at
use strict;
use warnings;
use Test::More;
use JQ::Lite;
my $json = q({
"text": "foo,bar,baz",
"users": [
{ "name": "Alice" },
{ "name": "Bob" }
],
"mixed": ["alpha beta", null, ["inne
y @comma = $jq->run_query($json, '.text | split(",")');
is_deeply($comma[0], [qw(foo bar baz)], 'split(",") breaks comma-separated string');
my @chars = $jq->run_query($json, '.users[0].name | split(
ars[0], [qw(A l i c e)], 'split("") returns individual characters');
my @array = $jq->run_query($json, '.mixed | split(" ")');
my $expected = [
[qw(alpha beta)],
[],
[[qw(inner)]],
{
my $json = q({
"numbers": [1, 2, 3, 4],
"user": { "name": "Alice" }
});
my $jq = JQ::Lite->new;
my @drop_0 = $jq->run_query($json, '.numbers | drop(0)');
my @drop_2 = $jq->run_query($json, '.n
umbers | drop(2)');
my @drop_5 = $jq->run_query($json, '.numbers | drop(5)');
my @non_array = $jq->run_query($json, '.user | drop(1)');
is_deeply($drop_0[0], [1, 2, 3, 4], 'drop(0) keeps all elements
use warnings;
use autodie qw(:all);
use File::Glob ':glob';
use File::Slurp;
use File::stat;
use JSON::MaybeXS;
use POSIX qw(strftime);
use Readonly;
Readonly my %config => (
github_user => 'nigelh
r_db => 'cover_db/cover.json',
output => 'cover_html/index.html'
);
# Read and decode coverage data
my $json_text = read_file($config{cover_db});
my $data = decode_json($json_text);
my $coverage_pc
ob("coverage_history/*.json");
# Cache historical data instead of reading for each file
my %historical_cache;
for my $hist_file (@history_files) {
my $json = eval { decode_json(read_file($hist_file)
package JQ::Lite::Expression;
use strict;
use warnings;
use JSON::PP (); # lightweight decoder for string literals
use Scalar::Util qw(looks_like_number);
# Internal constant used to signal that
next;
}
if ($char eq '"') {
my ($consumed, $value) = _consume_json_string($expr, $i);
return unless defined $consumed;
$i += $consumed;
ar;
$i++;
}
$path =~ s/\s+$//;
return ($i - $start, $path);
}
sub _consume_json_string {
my ($expr, $start) = @_;
my $i = $start;
my $len = length $expr;
my $
package JQ::Lite::Util;
use strict;
use warnings;
use JSON::PP ();
use List::Util qw(sum min max);
use Scalar::Util qw(looks_like_number);
use MIME::Base64 qw(encode_base64 decode_base64);
use Encod
;
my $JSON_DECODER = JSON::PP->new->utf8->allow_nonref;
my $FROMJSON_DECODER = JSON::PP->new->utf8->allow_nonref;
my $TOJSON_ENCODER = JSON::PP->new->utf8->allow_nonref;
sub _encode_json {
eturn $TOJSON_ENCODER->encode($value);
}
sub _decode_json {
my ($text) = @_;
if (defined $text && is_utf8($text, 1)) {
$text = encode('UTF-8', $text);
}
return $JSON_DECODER
ngs;
use Test::More;
use JQ::Lite;
my $json = <<'JSON';
{
"users": ["Alice", "Bob", "Carol"]
}
JSON
my $jq = JQ::Lite->new;
is_deeply([$jq->run_query($json, '.users | nth(0)')], ['Alice'], 'nth(0
jq->run_query($json, '.users | nth(1)')], ['Bob'], 'nth(1) is Bob');
is_deeply([$jq->run_query($json, '.users | nth(2)')], ['Carol'], 'nth(2) is Carol');
is_deeply([$jq->run_query($json, '.users | nth