I have a question regarding the to_json function. If I create
a string in script/console, and then apply the to_json
method, it will take the first and last double quote as part
of the string. Is this behaviour normal?
test = “my string”
test.to_json will return ““my string””
Yep. The rails console is printing test.to_json as a string value like
any other. Notice if you output the test variable itself, being a string
value, it’s surrounded by double quotes. The same thing happens to
test.to_json, with the added wrinkle that the value contains actual
double quote characters, which are escaped for display.