In Perl, checking a json decoded boolean value

Viewed 11003

Decoded JSON booleans are objects:

#!/usr/bin/env perl

use strict;
use warnings;

use Data::Dumper;
use JSON;

my $json_string = '{"boolean_field":true}';
my $decoded_json = from_json $json_string;

print Dumper $decoded_json;

Output:

$VAR1 = {
          'boolean_field' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' )
        };

From the JSON.pm documentation I know about the following three methods:

  • JSON::is_bool
  • JSON::true
  • JSON::false

However, for some silly reason I don't know how to determine if the value of 'boolean_field' in $decoded_json is true or false.

(Sorry for the very basic question; it's been driving me batty!)

1 Answers
Related