#!perl -l use 5.012; # strict, // use warnings; use JSON 4.0; use Data::Dumper; select STDERR; print $JSON::VERSION; my $json_text = q({"flag":true}); my $json = JSON->new; my $json_perl = $json->decode($json_text); print "Before boolean_values = ", Dumper($json_perl); $json->boolean_values(0,1); my $json_perl_after = $json->decode($json_text); print "After boolean_values = ", Dumper($json_perl_after); __END__ 4.02 Before boolean_values = $VAR1 = { 'flag' => bless( do{\(my $o = 1)}, 'JSON::PP::Boolean' ) }; After boolean_values = $VAR1 = { 'flag' => 1 };
Unlike what you said in Re^5: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?, I believe the documentation is quite explicit about version requirements for that method: the text "boolean_values (since version 4.0)" is in bold header text in the POD, which I interpret as claiming that the method has only been supported since version 4.0. The only clarification in that section of the docs that I would like: not using brackets for "optional" arguments in POD, especially in code blocks, because brackets have very well-defined meaning in Perl, and boolean_values(0,1) works whereas boolean_values([0,1]) as their example implies does not.
(Note also that your example code in Re^2: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object? swapped the order of the arguments, so a false would decode as 1 and a true as 0, which would cause you some difficulty at some point.)
In reply to Re^5: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?
by pryrt
in thread How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?
by Cody Fendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |