title: Having a problem sending JSON data from NodeJS/Express to EJS template
body: <p>Not able to access my JSON data in the ejs template. Uncaught SyntaxError thrown. Data is stored in a MySQL JSON table. Not sure why the ejs template is not able to parse the data. If I put the same data directly in the template(stub data), the chart displays as it should.
  Getting an <strong>Uncaught SyntaxError: Unexpected identifier</strong> error</p>
  
  <pre><code>app.use((req, res, next) =&gt; {
      var sql = "select data from market_data where id=1";
      var marketData = [];
      var myData = [];
  
      db.query(sql, function (err, res) {
          if (err) throw err;
          marketData = JSON.parse(res[0]['data']);
          console.log(marketData);
          for (let i=0;i&lt;marketData.length;i++) {
  
              myData.push({
                date: new Date(marketData[i]['DateTime']),
                open: marketData[i]['Open'],
                high: marketData[i]['High'],
                low: marketData[i]['Low'],
                close: marketData[i]['Close']
              });
            }
  
            app.locals.chartData = myData;
  
          });
          next();
  });
  
  app.set('view engine', 'ejs');
  app.set('views', path.join(__dirname, 'views'));
  app.use('/d3', express.static(__dirname+'/node_modules/d3/dist/'));
  app.use('/fc', express.static(__dirname+'/node_modules/d3fc/build/'));
  app.get('/', function (req, res) {  
      res.render('index', {chartData: app.locals.chartData});
  
  });
  </code></pre>
  
  <pre class="lang-html prettyprint-override"><code>&lt;div id="chart" style="width: 100%; height: 250px;"&gt;&lt;/div&gt;
          &lt;script type="text/javascript"&gt;
  
              var data = &lt;%- JSON.stringify(chartData) %&gt;
  
  
              var yExtent = fc.extentLinear()
              .accessors([
                  function(d) { return d.high; },
                  function(d) { return d.low; }
              ]);
  
              var xExtent = fc.extentDate()
              .accessors([function(d) { return d.date; }]);
  
              var gridlines = fc.annotationSvgGridline();
              var candlestick = fc.seriesSvgCandlestick();
              var multi = fc.seriesSvgMulti()
                  .series([gridlines, candlestick]);
  
              var chart = fc.chartSvgCartesian(
                  fc.scaleDiscontinuous(d3.scaleTime()),
                  d3.scaleLinear()
              )
              .yDomain(yExtent(data))
              .xDomain(xExtent(data))
              .plotArea(multi);
  
              d3.select('#chart')
              .datum(data)
              .call(chart);
          &lt;/script&gt;
  </code></pre>
  
  <pre><code>**console.log output from middleware (one record for brevity)
  { Day: 'Wed',
      Low: 2688.5,
      Date: '01-30-2019',
      High: 2689,
      Open: 2688.5,
      Time: '22:05:00',
      Close: 2688.75,
      Market: 'ES',
      Volume: 397,
      DateTime: '01-30-2019 22:05:00' }
  error:
  Uncaught SyntaxError: Unexpected identifier
  console.log from ejs template (two records shown for brevity)
  [{"date":"2019-02-03T23:00:00.000Z","open":2699.25,"high":2702.25,"low":2698,"close":2702.25},{"date":"2019-02-03T23:05:00.000Z","open":2702,"high":2702,"low":2700.5,"close":2701.75}]**
  </code></pre>