If I were you, I'd just use something much simpler like JSON::Tiny. And I'd file a patch request to have "my $TRUE" changed to "our $TRUE", etc.

Minimally, I've implemented this in JSON::Tiny version 0.33, uploaded to CPAN just a few minutes ago. my $TRUE... is now our $TRUE, so that users may explicitly override the return value for Booleans. The same goes for my $FALSE.

If there is sufficient call for it, I might also provide additional flexibility in _encode_value() by changing this line: return $value  ? 'true' : 'false' if $ref eq 'JSON::Tiny::_Bool'; to something like return $value  ? 'true' : 'false' if $ref eq $BOOL_CLASS; # A package global. Once we go too far down that road, however, people are going to start asking that $TRUE, $FALSE, and $BOOL_CLASS be implemented as object attributes for the JSON::Tiny object so that they can be manipulated on a per-instance basis... and that leads to becoming less '::Tiny'. ;)

For now just consider the following code:

use JSON::Tiny; $JSON::Tiny::FALSE = 0; $JSON::Tiny::TRUE = 1; my $j = JSON::Tiny->new(); # ... Booleans in JSON being decoded now return 0 and 1 instead of # JSON::Tiny::Bool objects

Update: Version 0.34 adds some tests and documentation on this advanced feature.


Dave


In reply to Re^4: Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects (source) by davido
in thread Making JSON::{PP,XS} not decode true/false to JSON::{PP,XS}::Boolean objects by sedusedan

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.