Created
March 26, 2012 04:39
-
-
Save olegwtf/2202961 to your computer and use it in GitHub Desktop.
Save JSON object keys ordering as is
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
use strict; | |
use Tie::IxHash; | |
use JSON::PP; | |
# magic start | |
my $obj_parser_sub = \&JSON::PP::object; | |
*JSON::PP::object = sub { | |
tie my %obj, 'Tie::IxHash'; | |
$obj_parser_sub->(\%obj); | |
}; | |
# magic end | |
use Data::Dumper; | |
my $res = decode_json('{"a":1,"b":2,"c":3}'); | |
print Dumper $res; | |
$res->{b} = 'xx'; | |
print encode_json($res), "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment