Created
May 4, 2014 01:32
-
-
Save harshavardhana/a9c0ce83ae752add9af6 to your computer and use it in GitHub Desktop.
Json parse validate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Borrowed from - http://search.cpan.org/~mlehmann/JSON-XS-3.01/bin/json_xs | |
# Modified for internal use in GlusterFS | |
use strict; | |
use Encode; | |
use JSON::XS; | |
my $opt_from = "json"; | |
my $opt_to = "null"; | |
my %F = ( | |
"json" => sub { | |
my $enc = | |
/^\x00\x00\x00/s ? "utf-32be" | |
: /^\x00.\x00/s ? "utf-16be" | |
: /^.\x00\x00\x00/s ? "utf-32le" | |
: /^.\x00.\x00/s ? "utf-16le" | |
: "utf-8"; | |
JSON::XS->new->decode (decode $enc, $_) | |
}, | |
); | |
my %T = ( | |
"null" => sub { "" }, | |
); | |
$F{$opt_from} | |
or die "$opt_from: not a valid fromformat\n"; | |
$T{$opt_to} | |
or die "$opt_from: not a valid toformat\n"; | |
{ | |
local $/; | |
binmode STDIN; # stupid perl sometimes thinks its funny | |
$_ = <STDIN>; | |
} | |
$_ = $F{$opt_from}->(); | |
$_ = $T{$opt_to}->(); | |
binmode STDOUT; | |
print $_; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment