title: How to manage json in html template sent through SSE flask
body: <p>I need to push json to my HTML template endlessly. On html template I want to manage this json and insert data from it to html page.
  Here is my code:</p>
  
  <pre><code>@app.route('/stream')
  def stream():
      def event_stream():
          counter = 0
          while True:
              yield "data: {}\n\n".format({"a": "1", "b": "2"})
              time.sleep(10)
      return Response(event_stream(), mimetype="text/event-stream")
  </code></pre>
  
  <p>and html template:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;My Webpage&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script&gt;
          var eventSource = new EventSource("/stream");
              eventSource.onmessage = function(e) {
              alert(e.data);
          };
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;   
  </code></pre>
  
  <p>For now <strong>alert</strong> does not work. And my json is displayed on HTML page even if to remove js script from html. How can I manipulate with json in my html?</p>