Ashley Raiteri
Ashley Raiteri

Reputation: 710

How do i disable utf-8 escaping in rails to_json output \u2013

Json is supposed to be able to be parsed with UTF characters included. In particular I'm talking about -. Or as it seems to be getting encoded: \u2013

This is for a json api output, and there's no need to be escaping these &'s that are in text fields. I wonder, how do people usually handle this in Rails 3?

Upvotes: 2

Views: 1257

Answers (2)

Yurii
Yurii

Reputation: 87

You can replace \u2013 with - in your string before writing it into JSON:

string = '\u2013'
string2 = string.gsub('\u2013', '-')
puts(string2) #Will output '-'

After, you can write string2 into yout JSON file.

Upvotes: 0

zed_0xff
zed_0xff

Reputation: 33227

\u2013 is not a &, it's a (EN_DASH)

Upvotes: 1

Related Questions