It:
"Joaqu\xEDn"
is a coded version of "Joaquín" based on ISO-8859-1, so it is not valid UTF-8, and your databases have the right to complain about it. If possible, fix your mobile clients to use UTF-8 in JSON; if you cannot do this, you can correct the encoding as follows:
params[:mobile_user][:name].force_encoding('iso-8859-1').encode!('utf-8')
on server. The problem with committing to the server is that you have to guess what the incoming encoding is, and your hunch may be wrong. It is not possible to reliably guess the encoding for a particular string; there is rchardet , but it does not work with the latest versions of Ruby and it seems to have been abandoned; You can fix this stone to work with modern Ruby. There are several more guessing libraries, but they all seem to have been abandoned too.
JSON text is always, by definition , Unicode and UTF-8 encoded by default:
3. Encoding JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.
Any clients that send you JSON that is not in UTF-8 are IMO broken, because almost everyone will assume that JSON will be UTF-8. Of course, there might be an encoding header somewhere that points to ISO 8859-1, or maybe the headers say UTF-8, although it's ISO 8859-1.
source share