It doesn't require JSON::PP or JSON::XS : it works perfectly well with JSON newer than v4.0:

#!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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.