1
0

Make json-pretty support URLs too

This commit is contained in:
Noah 2014-06-02 15:37:33 -07:00
parent 4f028a5680
commit e9e5328a0d

View File

@ -2,22 +2,28 @@
# json-pretty: Take a JSON file and pretty-print it.
#
# Usage: json-pretty <file.json>
# Usage: json-pretty <file.json or url>
#
# --Kirsle
use strict;
use warnings;
use LWP::Simple;
use JSON;
my $file = shift(@ARGV) or die "Usage: $0 <file.json>\n";
my $file = shift(@ARGV) or die "Usage: $0 <file.json or url>\n";
my $json = JSON->new->utf8->pretty();
my $text = "";
if ($file =~ /^https?:/i) {
$text = get $file;
} else {
local $/ = undef;
open(my $fh, "<", $file);
my $text = <$fh>;
$text = <$fh>;
close($fh);
}
my $data = $json->decode($text);
print $json->encode($data);