Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Brannigan: hash validation

by AnomalousMonk (Chancellor)
on Feb 14, 2018 at 12:51 UTC ( #1209133=note: print w/replies, xml ) Need Help??


in reply to Brannigan: hash validation

How about something like:

c:\@Work\Perl\monks\henzen>perl -wMstrict -MData::Dump -le "use JSON; ;; my $json = q{ { \"method\": \"xxx\", \"backend\": { \"client\": \"mytest009\", \"pw\": \"sdkjfhsfjhKJH87\" }, \"blah\": \"123\" }}; my $data = decode_json($json); dd $data; ;; my %valid = map { $_ => 1 } qw(method backend); my @invalid = grep { ! exists $valid{$_} } keys %$data; die qq{invalid keys(s) present: @invalid} if @invalid; " { backend => { client => "mytest009", pw => "sdkjfhsfjhKJH87" }, blah => 123, method => "xxx", } invalid keys(s) present: blah at -e line 1.
Of course, you have to know all the valid keys in advance, and it's only a top-level check, but maybe a starting point.


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1209133]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2018-07-19 23:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (421 votes). Check out past polls.

    Notices?