Cody Fendant has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|