sub handle_req_cgi{ eval { $log->info("pjb.cgi - Started function $function , user: $user_name"); $msg = UI::PJB::handleRequest($function, $parameters); 1; } //Response $tx->res->code($res_code); $tx->res->headers->content_type('application/json'); $tx->res->body(encode('UTF-8',$msg)); #THIS IS THE LINE which corrupts the msg but if I print just the msg without encode then #wide character warning is thrown by Mojo $tx->rendered; } #### handleRequest() # looks like this: { $jsonDecodedParameters = $J->decode($parameters); my $result = executeFunction($fun, $jsonDecodedParameters); if(ref $result eq ref {} && defined $result->{$HTTP_REQUEST_REDIRECT_URL_KEY}) { $jsonEncodedResult = $J->encode($result); returns this $jsonEncodedResult }