Update: As ikegami++ points out, the below won't work: as mentioned in the documentation, the different backends have incompatible object formats, so you can't mix-and-match. Without updating any modules, then, the only way to get at this functionality is to use JSON::PP as the backend (eg by setting the PERL_JSON_BACKEND environment variable), which will be at the cost of the speed benefit of the XS backend.

It should be possible to create a shim module that checks which of the available backends has a boolean_values function, and sets the backend accordingly. But if the code is deployed only in a single place that probably has little value.

I would expect the approach in my original answer below to work for classes that have a single master object and delegate to your choice of backends for the functionality - this is how I wrongly thought the JSON class worked.

Looking at the code for JSON-4.02, there is no mention of boolean_values, so I suspect you will need to call the JSON::PP function explicitly. This should work:

JSON::PP::boolean_values($json, 0, 1);

Alternatively, in your code you could inject the desired pass-through function into the JSON package:

{ package JSON { sub boolean_values { JSON::PP::boolean_values(@_); } }; }

.. or create your own application-specific JSON wrapper:

package Our::JSON; use base qw{ JSON }; sub boolean_values { JSON::PP::boolean_values(@_); } 1;

For extra points, inject the function in a BEGIN block only if !JSON->can('boolean_values'), so it automatically turns itself off when a JSON release catches up - that doesn't seem to have happened yet as of v4.10.

I'd recommend reporting this as an issue against the JSON package, it's possible I'm missing some good reason why this isn't already implemented - I suspect it involves no more than adding it to the @PublicMethods list, with corresponding docs and tests.


In reply to Re: Issues using boolean_values in JSON v4.02 by hv
in thread Issues using boolean_values in JSON v4.02 by bc3-au

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.