Skip to content

Instantly share code, notes, and snippets.

@hokaccha

hokaccha/jsonview.pl

Created Jun 16, 2009
Embed
What would you like to do?
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
use JSON::XS;
my $file = shift;
my $json_text;
unless ($file) {
print "Usage: jsonview.pl file\n";
exit;
}
if ($file =~ m!^https?://!) {
$json_text = get($file);
}
else {
open FH, $file or die "Cannot open $file: $!";
while(<FH>) {
$json_text .= $_;
}
}
my $json = new JSON::XS;
my $json_data = $json->decode($json_text);
print $json->pretty(1)->utf8->encode($json_data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.