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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.