title: Python to Javascript JSON objects (Flask)
body: <p>I am trying to create a simple Flask app where an array of integers is generated on the server and sent to the client. I want to view the array of integers in the console. Here is some sample (working) code in app.py:</p>
  
  <pre><code>from flask import Flask, render_template, request, url_for
  
  import random, json
  
  app = Flask(__name__)
  
  @app.route('/',  methods=['GET'])
  def form():
      json_helper = {}
      json_helper['randoms'] = [random.random() for _ in range(40)]
      json_object = json.dumps(json_helper)
      return render_template('sim0625.html', s_data=json_object)
  
  if __name__ == '__main__':
    app.run(debug=True)
  </code></pre>
  
  <p>And here is a snippet of the Javascript frontend:</p>
  
  <pre><code>&lt;script&gt;
  
    var data_xyz = {{ s_data|tojson }};
  
    var JSONObject = JSON.parse({{data_xyz}});
    console.log(JSONObject.randoms);  
  
   &lt;/script&gt;
  </code></pre>
  
  <p>Unfortunately, none of the javascript works on my webpage, and the error message shown is "Uncaught SyntaxError: Unexpected token u".</p>
  
  <p>Can someone please explain how to fix this? Thanks. My guess is the JSON objects are becoming strings.</p>
  
  <p>Note: The code from the front-end was adapted from this SO question: <a href="https://stackoverflow.com/questions/10926965/extracting-data-from-json-object-in-jquery-or-js">Extracting data from json object in jQuery or JS</a></p>