I’m trying to understand this behaviour around single/double quotes with JSON.parse, and how I can work around it.
pref1 = '{"foo":true}'
pref2 = "{'foo':true}"
JSON.parse(pref1)
=> {foo: true}
JSON.parse(pref2)
=> VM2021:1 Uncaught SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)
Even if I escape the single quotes in pref2 with a then i still get the same error. Why does it only work as a single-quoted string? And is there a way to convert prefs2 into a format that JSON.parse will be happy with?
thanks