The escape_javascript method in ActionView escapes the apostrophe \' as backslash apostrophe \\\', which gives errors when parsing as JSON.
\'
\\\'
For
Just call .to_json on a string and it will be escaped properly e.g.
"foo'bar".to_json