NAME
Data::Sah::Filter::perl::JSON::check_decode_array - Check that value can be decoded as JSON and it is an array
VERSION
This document describes version 0.007 of Data::Sah::Filter::perl::JSON::check_decode_array (from Perl distribution Sah-Schemas-JSON), released on 2022-11-15.
SYNOPSIS
Using in Sah schema's prefilters
(or postfilters
) clause
["str","prefilters",[["JSON::check_decode_array"]]]
Using with Data::Sah:
use Data::Sah qw(gen_validator);
my $schema = ["str","prefilters",[["JSON::check_decode_array"]]];
my $validator = gen_validator($schema);
if ($validator->($some_data)) { print 'Valid!' }
Using with Data::Sah:Filter directly:
use Data::Sah::Filter qw(gen_filter);
my $filter = gen_filter([["JSON::check_decode_array"]]);
# $errmsg will be empty/undef when filtering succeeds
my ($errmsg, $filtered_value) = $filter->($some_data);
Sample data and filtering results
"" # INVALID (String is not a valid JSON: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "(end of string)") at (eval 2346) line 8. ), unchanged (Empty string is not valid JSON)
"null" # INVALID (String is a valid JSON but not an encoded array), unchanged (Valid JSON but not an array)
"[1,2,3]" # valid, unchanged
"{\"a\":1}" # INVALID (String is a valid JSON but not an encoded array), unchanged (Valid JSON but not an array)
"\"foo\"" # INVALID (String is a valid JSON but not an encoded array), unchanged (Valid JSON but not an array)
"\"foo" # INVALID (String is not a valid JSON: unexpected end of string while parsing JSON string, at character offset 4 (before "(end of string)") at (eval 2351) line 8. ), unchanged (Invalid JSON, missing closing quote)
{} # INVALID (String is not a valid JSON: malformed JSON string, neither tag, array, object, number, string or atom, at character offset 0 (before "HASH(0x559dffd62610)") at (eval 2352) line 8. ), unchanged (Will become something like "HASH(0x560142d4e5e8)" and fail because it is not valid JSON)
DESCRIPTION
This is like the JSON::check_decode filter with the additional check that the decoded value is an array.
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Sah-Schemas-JSON.
SOURCE
Source repository is at https://github.com/perlancar/perl-Sah-Schemas-JSON.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2022, 2021 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Sah-Schemas-JSON
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.