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; }