Single and double quotes in json.parse
How can I pass a list of characters from Django to Javascript?
I'm passing a dictionary from Django to Javascript in the render function. In javascript I parse the data as always using the code
const dates = JSON.parse("{{dates|safe}}")
This works for numbers, but for strings I get some error
JSON.parse: unexpected character at line 1 column 2 of the JSON data
I could pinpoint the problem down to:
const this_works = JSON.parse('["1","2"]')
const this_throws = JSON.parse("['1','2']")
But I can't use the ' as the outermost character here as the {{}} notation seems to require ". What is the workaround to this problem?