0

My perl code:

#!/usr/bin/perl

if ( not -f "$ARGV[0]" ) { die "$!"; }

open(DATA,"$ARGV[0]") || die "$!";
$data = <DATA>;
close(DATA);

use JSON qw(decode_json);
$tidy = decode_json($data);

use Data::Dumper;
$Data::Dumper::Terse = 1;
#$Data::Dumper::Indent = 1;
$Data::Dumper::Sortkeys = 1;

print Dumper $tidy;

My JSON data:

[{"n":"v8_skillgames","i":"m1QhFLZ2CI","s":21254,"t":1522783462114739392,"m":false},{"n":"v8_breakaway","i":"kpOIPLacEa","s":6163,"t":1522783462115880128,"m":false}]

Unexpected Output:

[
  {
    'i' => 'm1QhFLZ2CI',
    'm' => bless( do{\(my $o = 0)}, 'JSON::PP::Boolean' ),
    'n' => 'v8_skillgames',
    's' => 21254,
    't' => '1522783462114739392'
  },
  {
    'i' => 'kpOIPLacEa',
    'm' => $VAR1->[0]{'m'},
    'n' => 'v8_breakaway',
    's' => 6163,
    't' => '1522783462115880128'
  }
]

I write some perl script to parse a single line JSON data. But I got unexpected output about 'm'. What's wrong?

Boontawee Home
  • 935
  • 7
  • 15
  • 2
    It's simply a boolean value. You should have no problem using it like any other hash element value, ignoring the fact that it's actually an object. – Borodin Apr 04 '18 at 19:20

1 Answers1

1

I search around google and found the solution:

use JSON::PP qw(decode_json);
$JSON::PP::true  = 'true';
$JSON::PP::false = 'false';
Boontawee Home
  • 935
  • 7
  • 15