public
Description: My personal script stash
Homepage: http://github.com/melo/scripts
Clone URL: git://github.com/melo/scripts.git
scripts / bin / x-json-parse
100755 31 lines (22 sloc) 0.411 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env perl
 
use strict;
use warnings;
use JSON::XS;
use Data::Dump qw( dd );
use encoding 'utf8';
 
my $file = $ARGV[0];
if (!$file) {
  warn("Usage: x-json-parse FILE\n");
  exit(1);
}
 
open(my $fh, '<:utf8', $file);
die("ERROR: could not open file '$file'\n") unless $fh;
 
local $/;
my $json = <$fh>;
close($fh);
 
binmode(\*STDOUT, ':utf8');
eval {
  dd(decode_json($json));
};
die if $@;
 
exit(0);