I am trying to parse a JSON string that is stored inside a cookie value that my Rails code is calling.
Rails is able to read the string up until the comma (',') that separates the two different key:value pairs in the string.
JavaScript:
var value1 = "v1";
var value2 = "v2";
var obj = { key1: value1, key2: value2 };
document.cookie = "cookiename="+JSON.stringify(obj);
Cookie:
Name: cookiename
Content: {"key1":v1,"key2":v2}
Rails:
@cookievalue = cookies[:cookiename]
Rails when calling @cookievalue in an erb <%= @cookievalue %> evaluates it as:
{"key1":v1
anything past the comma (',') that separates key1:v1,key2:v2 is missing.
Any ideas?
I tried this as straight text and it does the same thing with the first comma it encounters.
UPDATED Answered my own question below - needed to escape the comma separating the values using an encode() in JS.