I have an element with a rel attribute that contains a JSON string, something like:
rel='{"id":"#id#","name":"#name#"}'
Then in my javascript code I use $.parseJSONto analyze this data. This works correctly - except when it namecontains an apostrophe. I tried using jsStringFormatcoldfusion replace, which replaces all single quotes with escaped single quotes, etc., but I can't find the right solution. I know this is probably simple, but how do I get the code to correctly pass values using apostropes / single quotes using json?
This code works, but removes the apostrophes I would like to keep:
rel='{"id":"#id#","name":"#replace(name,"'","","all")#"}'
This does not work:
rel='{"id":"#id#","name":"#replace(name,"'","\'","all")#"}'
Doesn't:
rel='{"id":"#id#","name":"#replace(name,"'","\\\'","all")#"}'
Or:
rel='{"id":"#id#","name":"#replace(name,"'",""","all")#"}'
Or:
rel='{"id":"#id#","name":"#jsStringFormat(name)#"}'