my $json = JSON->new; $json->canonical(1); my $json_str = $json->encode($hashref); print $json_str; #### my $json_str = to_json($hashref, {canonical => 1});