Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created June 16, 2009 07:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hokaccha/130576 to your computer and use it in GitHub Desktop.
Save hokaccha/130576 to your computer and use it in GitHub Desktop.
#!/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