Skip Menu |
 

This queue is for tickets about the JSON-PP CPAN distribution.

Report information
The Basics
Id: 122270
Status: resolved
Priority: 0/
Queue: JSON-PP

People
Owner: Nobody in particular
Requestors: KSTAR [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: is_bool() incompatible with JSON::XS
Download (untitled) / with headers
text/plain 1.5k
Given a JSON object created via JSON::XS, JSON::PP::is_bool() cannot recognize a boolean. I found this while testing an existing script like so: % myScript.pl foo=bar this=true! Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON.pm JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm $JSON::VERSION 2.59 $JSON::MaybeXS::VERSION 1.002002 $JSON::PP::VERSION <undef> $JSON::XS::VERSION 2.34 % PERL_JSON_BACKEND=0 myScript.pl foo=bar this=true (ref JSON::XS::Boolean) Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm JSON.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON.pm JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm JSON/PP.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/JSON/PP.pm JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl-5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm $JSON::VERSION 2.59 $JSON::MaybeXS::VERSION 1.002002 $JSON::PP::VERSION 2.27300 $JSON::XS::VERSION 2.34 myScript.pl and file.json attached.
Subject: file.json
Download file.json
text/x-json 41b
{ "foo": "bar", "this": true }
Subject: myScript.pl
Download myScript.pl
text/x-perl 696b
#!/usr/bin/env perl require Config::Any::JSON; require JSON; my $config = Config::Any::JSON->load('file.json'); show($_, $$config{$_}) for sort keys %$config; printf(" %-25s %s\n", $_, $INC{$_}) for sort grep { /JSON/ } keys %INC; foreach my $var ( '$JSON::VERSION', '$JSON::MaybeXS::VERSION', '$JSON::PP::VERSION', '$JSON::XS::VERSION', ) { printf " %-25s %s\n", $var, eval $var // '<undef>'; } sub show { my ($key, $val) = @_; my $ref = ref $val; if (not $ref) { print "$key=$val\n"; } elsif (JSON::is_bool($ref)) { printf "%s=%s\n", $key, ($val eq JSON::true() ? 'true!' : 'false!'); } else { printf "%s=%s (ref %s)\n", $key, $val, $ref; } }
Download (untitled) / with headers
text/plain 1.7k
On Wed Jun 28 23:27:41 2017, KSTAR wrote: Show quoted text
> Given a JSON object created via JSON::XS, JSON::PP::is_bool() cannot > recognize a boolean. I found this while testing an existing script > like so: > > % myScript.pl > foo=bar > this=true! > Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm > JSON.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/JSON.pm > JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm > JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm > $JSON::VERSION 2.59 > $JSON::MaybeXS::VERSION 1.002002 > $JSON::PP::VERSION <undef> > $JSON::XS::VERSION 2.34 > % PERL_JSON_BACKEND=0 myScript.pl > foo=bar > this=true (ref JSON::XS::Boolean) > Config/Any/JSON.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/Config/Any/JSON.pm > JSON.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/JSON.pm > JSON/MaybeXS.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/JSON/MaybeXS.pm > JSON/PP.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/JSON/PP.pm > JSON/XS.pm /Users/kstar/perl5/perlbrew/perls/perl- > 5.19.0/lib/site_perl/5.19.0/darwin-2level/JSON/XS.pm > $JSON::VERSION 2.59 > $JSON::MaybeXS::VERSION 1.002002 > $JSON::PP::VERSION 2.27300 > $JSON::XS::VERSION 2.34 > > myScript.pl and file.json attached.
It looks like everything is too old. Please upgrade your JSON modules first.
Download (untitled) / with headers
text/plain 482b
On Wed Jun 28 10:27:41 2017, KSTAR wrote: Show quoted text
> Given a JSON object created via JSON::XS, JSON::PP::is_bool() cannot > recognize a boolean. I found this while testing an existing script > like so:
JSON::XS decided to handle booleans a different way to everybody else, which tends to result in confusion in places. Better is to use JSON::MaybeXS which will give you Cpanel::JSON::XS (with a fallback to JSON::PP), or to use any one of JSON::PP, Mojo::JSON or Cpanel::JSON::XS directly.
Download (untitled) / with headers
text/plain 1.2k
On Thu Jun 29 03:58:44 2017, MSTROUT wrote: Show quoted text
> On Wed Jun 28 10:27:41 2017, KSTAR wrote:
> > Given a JSON object created via JSON::XS, JSON::PP::is_bool() cannot > > recognize a boolean. I found this while testing an existing script > > like so:
> > JSON::XS decided to handle booleans a different way to everybody else, > which tends to result in confusion in places. > > Better is to use JSON::MaybeXS which will give you Cpanel::JSON::XS > (with a fallback to JSON::PP), or to use any one of JSON::PP, > Mojo::JSON or Cpanel::JSON::XS directly.
The latest JSON::XS (version 3) uses Types::Serialiser, whose Boolean class is-a JSON::PP::Boolean (except for its first version), and thus JSON::PP::is_bool should recognize its boolean objects. So, if it's possible for the original requester to update JSON::XS (from an obsolete version), this issue should be resolved for now. But if not for some reasons, it's a valid request to let JSON::PP::is_bool (and JSON::is_bool) recognize older JSON::XS::Boolean (and maybe the very first version of Types::Serialiser) that doesn't have is-a-JSON::PP::Boolean relationship, for better compatibility. Matt, I understand your feeling and position (as a JSON::MaybeXS originator), but your comment is rather off-topic. JSON::MaybeXS is already there in the myScript.pl.
Download (untitled) / with headers
text/plain 1.4k
On Thu Jun 29 09:10:53 2017, ISHIGAKI wrote: Show quoted text
> On Thu Jun 29 03:58:44 2017, MSTROUT wrote:
> > On Wed Jun 28 10:27:41 2017, KSTAR wrote:
> > > Given a JSON object created via JSON::XS, JSON::PP::is_bool() > > > cannot > > > recognize a boolean. I found this while testing an existing script > > > like so:
> > > > JSON::XS decided to handle booleans a different way to everybody > > else, > > which tends to result in confusion in places. > > > > Better is to use JSON::MaybeXS which will give you Cpanel::JSON::XS > > (with a fallback to JSON::PP), or to use any one of JSON::PP, > > Mojo::JSON or Cpanel::JSON::XS directly.
> > > The latest JSON::XS (version 3) uses Types::Serialiser, whose Boolean > class is-a JSON::PP::Boolean (except for its first version), and thus > JSON::PP::is_bool should recognize its boolean objects. > > So, if it's possible for the original requester to update JSON::XS > (from an obsolete version), this issue should be resolved for now. > > But if not for some reasons, it's a valid request to let > JSON::PP::is_bool (and JSON::is_bool) recognize older > JSON::XS::Boolean (and maybe the very first version of > Types::Serialiser) that doesn't have is-a-JSON::PP::Boolean > relationship, for better compatibility. > > Matt, I understand your feeling and position (as a JSON::MaybeXS > originator), but your comment is rather off-topic. JSON::MaybeXS is > already there in the myScript.pl.
Fixed with https://github.com/makamaka/JSON-PP/commit/366182d6eb8a445adac1a82892b7ed3b6803c336.
Download (untitled) / with headers
text/plain 1.6k
On Sun Dec 02 22:59:15 2018, ISHIGAKI wrote: Show quoted text
> On Thu Jun 29 09:10:53 2017, ISHIGAKI wrote:
> > On Thu Jun 29 03:58:44 2017, MSTROUT wrote:
> > > On Wed Jun 28 10:27:41 2017, KSTAR wrote:
> > > > Given a JSON object created via JSON::XS, JSON::PP::is_bool() > > > > cannot > > > > recognize a boolean. I found this while testing an existing > > > > script > > > > like so:
> > > > > > JSON::XS decided to handle booleans a different way to everybody > > > else, > > > which tends to result in confusion in places. > > > > > > Better is to use JSON::MaybeXS which will give you Cpanel::JSON::XS > > > (with a fallback to JSON::PP), or to use any one of JSON::PP, > > > Mojo::JSON or Cpanel::JSON::XS directly.
> > > > > > The latest JSON::XS (version 3) uses Types::Serialiser, whose Boolean > > class is-a JSON::PP::Boolean (except for its first version), and thus > > JSON::PP::is_bool should recognize its boolean objects. > > > > So, if it's possible for the original requester to update JSON::XS > > (from an obsolete version), this issue should be resolved for now. > > > > But if not for some reasons, it's a valid request to let > > JSON::PP::is_bool (and JSON::is_bool) recognize older > > JSON::XS::Boolean (and maybe the very first version of > > Types::Serialiser) that doesn't have is-a-JSON::PP::Boolean > > relationship, for better compatibility. > > > > Matt, I understand your feeling and position (as a JSON::MaybeXS > > originator), but your comment is rather off-topic. JSON::MaybeXS is > > already there in the myScript.pl.
> > > Fixed with https://github.com/makamaka/JSON- > PP/commit/366182d6eb8a445adac1a82892b7ed3b6803c336.
Released JSON::PP 4.00 with this. Thanks.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.