<p dir="ltr">Everyone has those problems, that's why you should use Cpanel::JSON::XS instead </p>
<div class="gmail_quote">On Jan 14, 2016 22:36, "Michael R. Davis via Houston" <<a href="mailto:houston@pm.org">houston@pm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="color:#000;background-color:#fff;font-family:Courier New,courier,monaco,monospace,sans-serif;font-size:16px"><div dir="ltr">Perl Folks,</div><div dir="ltr">I have a compatibility issue with JSON::PP and JSON::XS that I just cannot figure out.</div><div dir="ltr"> </div><div dir="ltr">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.</div><div dir="ltr"> </div><div dir="ltr">I have to use JSON::PP for it's sort_by capability in sending JSON but I use JSON::XS for performance in decoding.</div><div dir="ltr"> </div><div dir="ltr">This is my reduced code to expose the issue</div><div dir="ltr"> </div><div dir="ltr">  my $json=JSON::PP->new->allow_nonref->allow_blessed;<br>  #limit data to the single Boolean for test case</div><div dir="ltr">  $data_input   = $data_input->{"aZone"}->{"IsActive"};<br>  print ref($json), "\n";<br>  print Dumper($data_input);<br></div><div dir="ltr">  my $json_input  = $json->encode($data_input);<br></div><div dir="ltr">  print $json_input ,"\n";<br>  exit;<br></div><div dir="ltr">This shows the encode method returns a "null" when I expect a "true".</div><div dir="ltr"> </div><div dir="ltr">JSON::PP<br>$VAR1 = bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' );<br>null</div><div dir="ltr"> </div><div dir="ltr">I tried to reproduce but I cannot with a simple script so I'm turning to the Perl Mongers for any help?</div><div dir="ltr"> </div><div dir="ltr">Mike</div><div dir="ltr"> </div><div dir="ltr">Similar code that does not reproduce the issue.</div><div dir="ltr"> </div><div dir="ltr">perl -e '<br>use strict;<br>use warnings;<br>use Data::Dumper qw{Dumper};<br>use JSON::XS qw{};<br>use JSON::PP qw{};</div><div dir="ltr">my $json=q[{"true":true,"false":false,"null":null}];<br>my $xs=JSON::XS->new->allow_nonref;<br>my $pp=JSON::PP->new->allow_nonref->allow_blessed->convert_blessed;<br>print "XS: ", $xs->VERSION, "\n";<br>print "PP: ", $pp->VERSION, "\n";<br>my $data=$xs->decode($json);<br>print Dumper($data);<br>my $trip = $pp->encode($data);<br>my $sorter={true=>1, false=>2, null=>3};<br>$pp->sort_by(sub {$sorter->{$JSON::PP::a} <=> $sorter->{$JSON::PP::b}});<br>print $json, "\n";<br>'<br></div><div dir="ltr">XS: 2.27<br>PP: 2.24000<br>$VAR1 = {<br>          'false' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ),<br>          'true' => bless( do{\(my $o = 1)}, 'JSON::XS::Boolean' ),<br>          'null' => undef<br>        };<br>{"true":true,"false":false,"null":null}<br><br></div></div></div><br>_______________________________________________<br>
Houston mailing list<br>
<a href="mailto:Houston@pm.org">Houston@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/houston" rel="noreferrer" target="_blank">http://mail.pm.org/mailman/listinfo/houston</a><br>
Website: <a href="http://houston.pm.org/" rel="noreferrer" target="_blank">http://houston.pm.org/</a><br></blockquote></div>