Converting some simple JSON:

{ "adult": false, "backdrop_path": "/tdo5GwYAsdRkYTTMpXM9aZu8DlH.jpg", "genre_ids": [ 53, 80, 28 ], "id": 11258, "original_language": "en", "original_title": "Hard Rain", "overview": "Get swept up in the action as an armored car driver ( +Christian Slater) tries to elude a gang of thieves (led by Morgan Fre +eman) while a flood ravages the countryside. Hard Rain is \"a wild, t +hrilling, chilling action ride\" filled with close calls, uncertain l +oyalties and heart-stopping heroics.", "popularity": 12.186, "poster_path": "/hhG5ppaEQIV83GbUVfPlBMDFvVu.jpg", "release_date": "1998-01-16", "title": "Hard Rain", "video": false, "vote_average": 5.8, "vote_count": 519 }

and the false value comes out as an object  bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ) when converted to Perl data:

$VAR1 = { 'original_language' => 'en', 'vote_count' => 519, 'overview' => 'Get swept up in the action as an armored car +driver (Christian Slater) tries to elude a gang of thieves (led by Mo +rgan Freeman) while a flood ravages the countryside. Hard Rain is "a +wild, thrilling, chilling action ride" filled with close calls, uncer +tain loyalties and heart-stopping heroics.', 'id' => 11258, 'title' => 'Hard Rain', 'video' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ), 'backdrop_path' => '/tdo5GwYAsdRkYTTMpXM9aZu8DlH.jpg', 'release_date' => '1998-01-16', 'vote_average' => '5.8', 'adult' => $VAR1->{'video'}, 'poster_path' => '/hhG5ppaEQIV83GbUVfPlBMDFvVu.jpg', 'original_title' => 'Hard Rain', 'popularity' => '12.186', 'genre_ids' => [ 53, 80, 28 ] };

Which is a little unsightly and hard to understand as a human. I mean I know it can be tested as a true or false value, but it's much harder to read.

What's worse is, the JSON boolean for 'adult' is now  $VAR1->{'video'} which means I have to refer to the previous object to even figure out what it is. Not a problem in a small object like this but in a bigger one it will be very frustrating.

Is there some way these things can be converted to simple 1 and 0 values? I swear I've read the documentation multiple times and can't see it.

Or can I get Data::Dumper to do it for me?


In reply to How do I make the JSON module convert true/false to 1/0 instead of a blessed Boolean object? by Cody Fendant

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.