title: What is the difference between jsonify and tojson in Flask?
body: <p>I want to use some data from my Flask view in a JavaScript block in my template.  I tried using <code>jsonify</code> and <code>tojson</code>, but that gave an error.  What is the difference between the two?  How do I pass JSON to JavaScript in a template?</p>
  
  <pre><code>@app.route('/stocks')
  def stocks():
      stocks = jsonify({"aapl":{"price":700, "volume":5000000}, "goog":{"price":655, "volume":9750000}})
      return render_template("stocks.html", stocks=stocks)
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;script&gt;var zipcodes = {{ stocks|tojson }};&lt;/script&gt;
  </code></pre>
  
  
  
  <pre><code>TypeError: &lt;Response 21 bytes [200 OK]&gt; is not JSON serializable
  </code></pre>