ly::Object::TimeseriesResult;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Object::ListAttackReportMeta;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
DdosProtectionInvalidRequest;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Fastly::Object::SignalReport;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Fastly::Object::AttackSignal;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Fastly::Object::TopWorkspace;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Fastly::Object::DimensionUrl;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
Fastly::Object::ValuesMisses;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
ogRecordsResponseMetaFilters;
require 5.6.0;
use strict;
use warnings;
use utf8;
use JSON::MaybeXS qw(decode_json);
use Data::Dumper;
use Module::Runtime qw(use_module);
use Log::Any qw($log);
use Da
f = shift;
my $_hash = decode_json(JSON()->new->allow_blessed->convert_blessed->encode($self));
return $_hash;
}
# used by JSON for serialization
sub TO_JSON {
my $self = shift;
my $
serialize the data
while ( my ($_key, $_type) = each %{$self->openapi_types} ) {
my $_json_attribute = $self->attribute_map->{$_key};
my $_is_nullable = ($self->openapi_nullable->{
use strict;
use warnings;
use Test::More;
use JQ::Lite;
my $json = q({
"title": "Hello World",
"tags": ["Perl", "JSON", "CLI"],
"users": [
{"name": "Alice"},
{"name": "Bob"}
]
});
my
json, '.title | lower');
is($scalar_lower[0], 'hello world', 'lower converts scalar to lowercase');
my @array_upper = $jq->run_query($json, '.tags | upper');
is_deeply($array_upper[0], ['PERL', 'JSON
>run_query($json, '.users[] | .name | lower');
is_deeply(\@pipeline_lower, ['alice', 'bob'], 'lower works in pipelines with flattened arrays');
my @scalar_titlecase = $jq->run_query($json, '.title |
;
use JQ::Lite;
use JSON::PP qw(encode_json decode_json);
my $jq = JQ::Lite->new;
my $json = encode_json({ matrix => [ [1, 2, 3], [4, 5, 6] ] });
my @result = $jq->run_query($json, '.matrix | transp
sult[0], $expected, 'transpose pivots arrays of arrays');
$json = encode_json({ jagged => [ [1, 2], [3] ] });
@result = $jq->run_query($json, '.jagged | transpose');
$expected = [ [1, 3] ];
is_deeply
transpose truncates to the shortest row');
$json = encode_json({ numbers => [1, 2, 3] });
my $decoded = decode_json($json);
@result = $jq->run_query($json, '.numbers | transpose');
is_deeply($result[
use strict;
use warnings;
use Test::More;
use JSON::PP;
use JQ::Lite;
my $json = q({
"title": "Hello World!",
"tags": ["perl", "json", "cli"],
"names": ["Alice", "Bob", "Alfred"],
"mixed": ["
_title = $jq->run_query($json, '.title | startswith("Hello")');
ok($starts_title[0], 'startswith() returns true for matching prefix');
my @starts_false = $jq->run_query($json, '.title | startswith("W
ends_title = $jq->run_query($json, '.title | endswith("World!")');
ok($ends_title[0], 'endswith() returns true for matching suffix');
my @ends_false = $jq->run_query($json, '.title | endswith("Hello"
re;
use FindBin;
use lib "$FindBin::Bin/../lib";
use JQ::Lite;
my $jq = JQ::Lite->new;
my $json = <<'JSON';
[
{ "name": "Alice", "team": "A" },
{ "name": "Bob", "team": "B" },
{ "name": "Car
: "A" },
{ "name": "Dave", "team": "B" },
{ "name": "Eve", "team": "A" }
]
JSON
my @res = $jq->run_query($json, 'group_count(team)');
is_deeply(
$res[0],
{
A => 3,
B =
> 2,
},
'group_count(team) tallies members per team'
);
@res = $jq->run_query($json, 'group_count(nickname)');
is_deeply(
$res[0],
{
null => 5,
},
'group_count on mis
}\n",
);
is($stdout, "[{\"name\":\"Alice\"},{\"name\":\"Bob\"}]\n", '--slurp aggregates multiple JSON documents');
like($stderr, qr/^\s*\z/, 'no warnings emitted when slurping multiple documents');
i
=> "{\"name\":\"Carol\"}\n",
);
is($stdout, "[{\"name\":\"Carol\"}]\n", '--slurp wraps a single JSON document in an array');
like($stderr, qr/^\s*\z/, 'no warnings emitted when slurping a single doc
use Encode qw(decode);
use JQ::Lite;
my $json = decode('UTF-8', '"こんにちは!"');
my $jq = JQ::Lite->new;
my @results = eval { $jq->run_query($json, '@uri') };
my $error = $@;
is($error,
my ($json, $query) = @_;
return [$jq->run_query($json, $query)];
}
sub encode_json {
my ($data) = @_;
require JSON::PP;
return JSON::PP::encode_json($data);
}
my $json = <<'JSON';
{
"details": {
"dimensions": {
"width": 10,
"height": 20
}
}
}
JSON
my $res = run_query($json, 'setpath(["details", "dimensions", "depth"]; 5)');
is_deeply($res->[0], {
nam
depth => 5,
},
},
}, 'setpath() adds missing nested key');
$res = run_query($json, 'setpath(["details", "dimensions", "width"]; 42)');
is_deeply($res->[0], {
name => 'widg
::More tests => 5;
use JSON::PP;
use JQ::Lite;
my $jq = JQ::Lite->new;
# --- 1. Nested object with arrays and booleans
my $json1 = '{"user":{"name":"Alice","tags":["perl","json"],"active":true}}';
m
y @result1 = $jq->run_query($json1, 'paths');
is_deeply(
$result1[0],
[
[ 'user' ],
[ 'user', 'active' ],
[ 'user', 'name' ],
[ 'user', 'tags' ],
[ 'use
nested key/index in order',
);
# --- 2. Mixed array contents
my $json2 = '[1,{"foo":[2,null]}]';
my @result2 = $jq->run_query($json2, 'paths');
is_deeply(
$result2[0],
[
[ 0 ],
n/../lib";
use JQ::Lite;
my $jq = JQ::Lite->new;
my $json_nested = <<'JSON';
[[1, 2], [3, [4, 5]], 6]
JSON
my @depth_one = $jq->run_query($json_nested, 'flatten_depth(1)');
is_deeply(
$depth_on
n_query($json_nested, 'flatten_depth(2)');
is_deeply(
$depth_two[0],
[1, 2, 3, 4, 5, 6],
'flatten_depth(2) flattens two levels of nesting'
);
my @depth_zero = $jq->run_query($json_nested,
>run_query($json_nested, 'flatten_depth');
is_deeply(
$default_depth[0],
[1, 2, 3, [4, 5], 6],
'flatten_depth defaults to a depth of 1 when omitted'
);
my $json_mixed = <<'JSON';
[[{"name
e;
my $json_objects = q([
{ "value": 10 },
{ "value": 30 },
{ "value": 20 }
]);
my $json_even = q([
{ "score": 1 },
{ "score": 3 },
{ "score": 5 },
{ "score": 7 }
]);
my $json_mixed =
{ "score": 3 }
]);
my $json_booleans = q([
{ "flag": true },
{ "flag": false },
{ "flag": true }
]);
my $json_entire_item = q([1, "2", 3, "not a number"]);
my $json_no_numeric = q([
{ "va
dian_objects) = $jq->run_query($json_objects, 'median_by(.value)');
is($median_objects, 20, 'median_by over projected values');
my ($median_even) = $jq->run_query($json_even, 'median_by(.score)');
is
gs;
use Test::More;
use JQ::Lite;
my $json = <<'JSON';
{
"items": [[1, 2], [3], [], [4, 5]]
}
JSON
my $jq = JQ::Lite->new;
my @results = $jq->run_query($json, '.items | flatten');
is_deeply(\@res