I am having a json like below.
$response = {"entries":[{"content":{"eStatus":0,"id":"0","enabled":false,"isOK":false,}}]}
$responseContent = from_json($response);
when i am using from_json or decode_json within my perl code I get following as the converted json.
'content' => {
'id' => '0',
'esrsVeAddress' => '',
'isOK' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
'enabled' => $VAR1->{'entries'}[0]{'content'}{'isOK'},
'eStatus' => 0
}
When value of element is not boolean ( true/false ) conversion happens properly but when its boolean then output is corrupted.
If you will see value of element 'enabled' and 'isOK' both are wrong.
Am i using wrong function 'from_json' or 'decode_json' here.
Any suggestions or guidance is appreciated.
This is the way i am trying to use value of element isOK and enabled.
if ( $isOK = $responseContent->{'entries'}[0]->{'content'}-> {'isOK'} eq "1" ) {
c4lx_log "value is found to be true and so do some business logic";
}
else {
c4lx_log "value is found to be false and so dont do anything here";
}
NOTE: Input to fucntion 'from_json' or 'decode_json' is coming from the REST response in format as shown above. I have verified that input is passed correctly and as expected. Its just the conversion that is issue here.
falseis truthy in Perl. JSON.pm creates a wrapper for boolean values so they mean the same thing in Perl as they do in the original JSON. See metacpan.org/pod/JSON#true-false