Skip to content

Instantly share code, notes, and snippets.

@luzluna
Created May 7, 2015 06:20
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 luzluna/1576fca2ae7f21333195 to your computer and use it in GitHub Desktop.
Save luzluna/1576fca2ae7f21333195 to your computer and use it in GitHub Desktop.
Perl JSON perserve order
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
@dani
Copy link

dani commented Feb 26, 2024

You just saved me a lot of time with this ! Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment