In my controller, the following works (prints “oké”)
puts obj.inspect
But this doesn’t (renders “ok\u00e9”)
render :json => obj
Apparently the to_json method escapes unicode characters. Is there an option to prevent this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you dig through the source you’ll eventually come to
ActiveSupport::JSON::Encodingand theescapemethod:The various
gsubcalls are forcing non-ASCII UTF-8 to the\uXXXXnotation that you’re seeing. Hex encoded UTF-8 should be acceptable to anything that processes JSON but you could always post-process the JSON (or monkey patch in a modified JSON escaper) to convert the\uXXXXnotation to raw UTF-8 if necessary.I’d agree that forcing JSON to be 7bit-clean is a bit bogus but there you go.
Short answer: no.