package Mojolicious::Plugin::Vparam::JSON;
use Mojo::Base -strict;
use Mojolicious::Plugin::Vparam::Common qw(decode_json);
use Mojo::JSON;
sub parse_json($) {
my $str = shift;
return undef
e_json $str;
}
sub check_json($) {
return 'Wrong format' unless defined $_[0];
return 0;
}
sub register {
my ($class, $self, $app, $conf) = @_;
$app->vtype(
json
=>
pre => sub { parse_json $_[1] },
valid => sub { check_json $_[1] },
);
return;
}
1;
trict;
use Mojolicious::Plugin::Vparam::Common qw(load_class decode_json);
use Mojolicious::Plugin::Vparam::Numbers;
use Mojo::JSON;
use Digest::MD5 qw(md5_hex);
use Encode
# JSON format
my $json = decode_json $str;
if( $json and 'ARRAY' eq ref($json)) {
$full = sprintf '%s : %s , %s',
$json->[2]//'', $json->
[3]//'', $json->[4]//'';
$address = $json->[2];
$lon =
Mojolicious::Plugin::Vparam::Numbers::parse_number $json->[3];
$lat =
# JSON Pointer
unless(exists $vars->{json}) {
$vars->{json} =
Mojolicious::Plugin::Vparam::JSON::parse_json(
}
if( $vars->{json} ) {
$vars->{pointer} //=
Mojo::JSON::Pointer->new( $vars->{json} );
if( $vars->{pointe
# JSON Pointer
unless (exists $vars->{json}) {
$vars->{json} =
Mojolicious::Plugin::Vparam::JSON::parse_json(
ORT = qw(trim);
our @EXPORT_OK = qw(char_shift find_modules load_class params decode_json);
our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
our $CHAR_SHIFT = ord('A') - 10;
sub tr
json($) {
my $json = shift;
# JSON must be blob
$json = encode utf8 => $json if is_utf8 $json;
return eval{ Mojo::JSON::decode_json( $json ) }
if Mojo::JSON->can('decode_json
');
return @{ Mojo::JSON->new->decode( $json ) }
if Mojo::JSON->can('new');
};
1;
alues
=item *
Support HTML checkbox as bool
=item *
Simple JSON values extraction and validation using JSON Pointer from
L<Mojo::JSON::Pointer>.
=item *
Simple XML/HTML values extraction and val
is not work if you site has i18n.
=head2 json
JSON incapsulated as form parameter.
=head2 address
Location address. Two forms are parsed: string and json.
Can verify adress sign to trust source.
turn
formatted scalar.
=head2 jpath
If you POST data not form but raw JSON you can use JSON Pointer selectors
from L<Mojo::JSON::Pointer> to get and validate parameters.
# POST data contains: