I am trying to pass simple data from flask to javascript file I am following this answer Passing a JSON object from Flask to JavaScript
But i got Uncaught SyntaxError: Unexpected token { in JSON at position 1 at JSON.parse ()
var user = JSON.parse('{{ data | tojson}}');
var grade=user.grade;
console.log(grade);
my python file have code
@app.route("/quiz/0")
def quizFirst():
data={"grade":"0"}
return render_template('quiz.html',data=data)
the token { is not recognizable by javascript in js file, Any idea what i am missing.
quiz.htmlor is it in a separate .js file?var user = JSON.parse('{{ data | tojson}}');I don't know if maybe that's meant to get replaced somehow, but as written it will literally try to parse that string. So JSON.parse sees{{and immediately errors.