I am facing an issue with the encode_json function in use JSON::XS qw(encode_json);
. we have a web based project with Perl, JavaScript, jQuery and MySQL as the back end.
In a particular screen in the application, the name of the user is distorted.
The problem is the user name is in spanish and has accented characters. The table where we are saving the DB is old table and has charset latin 1, but when I am fetching the data, i am using cast and convert and encoding it to UTF-8 format.
select CONVERT(CAST(CONVERT(u.last_name USING latin1) AS BINARY) USING utf8) AS last_name from user where user_id = 'XXX'
In the structure where I am storing the DB results, the data is appearing fine.
{ last_name => Cvas García}
this structure is passed to javascript function which renders the page
$data_json = encode_json( $data )
When I print $data_json
, the accented characters are distorted once again.
"user_permissions":[{"last_name":"Cvas GarcÃa"}]},
Can anyone help me how can I solve this, either in the Mysql or perl or javascript code?