I am trying to use JSON module (from CPAN) to encode & decode JSON data in my application. The encoding part is fine but when I'm trying to decode data the boolean values decode fine, albeit in a little weird way. Let me illustrate that with an example. I get this data back from my server as JSON:
{"value":[{"name":"THICNT","value":"1","secure":false,"path":"/","doma +in":"www.google.com","class":"org.openqa.selenium.internal.ReturnedCo +okie"},{"name":"NID","value":"34=pqQMsEqv3oAfy8-qWv-WEYBusldqUSoe_9Tg +iSoaN0itw7","secure":false,"path":"/","domain":".google.com","class": +"org.openqa.selenium.internal.ReturnedCookie"},{"name":"PREF","value" +:"ID=3f5070f587c10823:U=4e8ab4b3b6576160:TM=1271918988:LM=1271918988: +S=NZ9UTF7eCxicziqM","secure":false,"path":"/","domain":".google.com", +"class":"org.openqa.selenium.internal.ReturnedCookie"}]}
and when I decode it by JSON->new->allow_nonref(1)->utf8(1)->decode on the above stream, I get the following output:
$VAR1 = [ { 'domain' => 'www.google.com', 'value' => '1', 'secure' => bless( do{\(my $o = 0)}, 'JSON::XS::Boolean' ) +, 'name' => 'THICNT', 'class' => 'org.openqa.selenium.internal.ReturnedCookie', 'path' => '/' }, { 'domain' => '.google.com', 'value' => '34=pqQMsEqv3oAfy8-qWv WEYBusldqUSoe_9TgiSoaN0i +tw7', 'secure' => $VAR1->[0]{'secure'}, 'name' => 'NID', 'class' => 'org.openqa.selenium.internal.ReturnedCookie', 'path' => '/' }, { 'domain' => '.google.com', 'value' => 'ID=3f5070f587c10823:U=4e8ab4b3b6576160:TM=1271 +918988:LM=1271918988:S=NZ9UTF7eCxicziqM', 'secure' => $VAR1->[0]{'secure'}, 'name' => 'PREF', 'class' => 'org.openqa.selenium.internal.ReturnedCookie', 'path' => '/' } ];

As you can see it is an array of all the cookies, but that is irrelevant. What is relevant is that the 'secure' key's value is boolean. And the first occurrence of secure's value is an actual blessed reference & the remaining such occurrences are references to that first blessed reference.

So my question is simple - how can I invoke decode so that each boolean value is its own blessed reference rather than a reference to an already existing value? Or is that just by design & that is the only way JSON.pm decodes data?


In reply to JSON module & decoding boolean data by rovingeyes

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.