Created
May 7, 2015 06:20
-
-
Save luzluna/1576fca2ae7f21333195 to your computer and use it in GitHub Desktop.
Perl JSON perserve order
This file contains 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
use Tie::IxHash; | |
use JSON; | |
use Data::Dump qw/dump/; | |
my $json = '{"test":"test","test2":"test2","test4":"test4","test3":"test3"}'; | |
my $obj_parser_sub = \&JSON::PP::object; | |
*JSON::PP::object = sub { | |
tie my %obj, 'Tie::IxHash'; | |
$obj_parser_sub->(\%obj); | |
}; | |
$ret = decode_json($json); | |
print dump($ret); | |
------ | |
{ | |
# tied Tie::IxHash | |
test => "test", | |
test2 => "test2", | |
test3 => "test3", | |
test4 => "test4", | |
} | |
works well |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You just saved me a lot of time with this ! Thank you :)