use JSON::PP; my $json_text=$JSON::PP->new()->sort_by(sub { $JSON::PP::a cmp $JSON::PP::b })->encode(\%UDIoutput);