Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?

by ikegami (Patriarch)
on Jan 03, 2022 at 06:49 UTC ( [id://11140091]=note: print w/replies, xml ) Need Help??


in reply to How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?

Use boolean_values

  • Comment on Re: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object?
by Cody Fendant (Hermit) on Jan 03, 2022 at 07:40 UTC

    Thanks, that looks like what I should be doing all right.

    But doing this:

    use JSON; my $j = JSON->new(); $j->boolean_values( 1, 0 );

    Gets me Can't locate object method "boolean_values" via package "JSON"

    What am I doing wrong?

      Hello Cody Fendant

      grepping CPAN it seems the method ships with JSON::PP and you can read about it

      # Note that JSON version 2.0 and above will automatically use # JSON::XS or JSON::PP, so you should be able to just: use JSON;

      This probably means you have also JSON::XS installed and it is loaded first

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Both JSON::PP and JSON::XS support boolean_values, and the error message said the method wasn't found in JSON, not JSON::XS.

      works fine for me, JSON v4.03, JSON::PP v4.06

      Are you using version 4+?

        I was using the very latest JSON, but not the very latest JSON::PP, so that's a factor. Upgrading JSON::PP and specifically using that has fixed it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140091]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found