We are currently experiencing an issue with the encode_json function while using use JSON::XS qw(encode_json);
. Our web-based project is built on Perl, JavaScript, jQuery, and MySQL as the backend.
In one specific screen within the application, the user's name is displaying inaccurately.
The problem arises due to the fact that the user's name is in Spanish and includes accented characters. The database table where we store this information follows an old schema with a charset of latin1. However, during data retrieval, we convert and encode it into 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 storage structure for the database results, everything looks correct.
{ last_name => Cvas García}
This structured data is passed to a JavaScript function responsible for rendering the page.
$data_json = encode_json( $data )
However, when printing $data_json
, the accented characters once again appear distorted.
"user_permissions":[{"last_name":"Cvas GarcÃa"}]},
We are seeking assistance in resolving this issue, whether it involves adjustments in MySQL, Perl, or JavaScript code.