[pm-h] JSON:PP compatibility issue with JSON::XS::Boolean

Michael R. Davis mrdvt92 at yahoo.com
Thu Jan 14 13:36:41 PST 2016


Perl Folks,I have a compatibility issue with JSON::PP and JSON::XS that I just cannot figure out. When encoding a JSON::XS::Boolean object with JSON::PP, I'm getting JSON "null" instead of JSON "true" or "false".  I Googled but could not find anything on this issue. I have to use JSON::PP for it's sort_by capability in sending JSON but I use JSON::XS for performance in decoding. This is my reduced code to expose the issue   my $json=JSON::PP->new->allow_nonref->allow_blessed;
  #limit data to the single Boolean for test case  $data_input   = $data_input->{"aZone"}->{"IsActive"};
  print ref($json), "\n";
  print Dumper($data_input);
  my $json_input  = $json->encode($data_input);
  print $json_input ,"\n";
  exit;
This shows the encode method returns a "null" when I expect a "true". JSON::PP
$VAR1 = bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' );
null I tried to reproduce but I cannot with a simple script so I'm turning to the Perl Mongers for any help? Mike Similar code that does not reproduce the issue. perl -e '
use strict;
use warnings;
use Data::Dumper qw{Dumper};
use JSON::XS qw{};
use JSON::PP qw{};my $json=q[{"true":true,"false":false,"null":null}];
my $xs=JSON::XS->new->allow_nonref;
my $pp=JSON::PP->new->allow_nonref->allow_blessed->convert_blessed;
print "XS: ", $xs->VERSION, "\n";
print "PP: ", $pp->VERSION, "\n";
my $data=$xs->decode($json);
print Dumper($data);
my $trip = $pp->encode($data);
my $sorter={true=>1, false=>2, null=>3};
$pp->sort_by(sub {$sorter->{$JSON::PP::a} <=> $sorter->{$JSON::PP::b}});
print $json, "\n";
'
XS: 2.27
PP: 2.24000
$VAR1 = {
          'false' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),
          'true' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ),
          'null' => undef
        };
{"true":true,"false":false,"null":null}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20160114/732a0dcc/attachment.html>


More information about the Houston mailing list