title: How can I consume a stream of json chunks from http endpoint?
body: <p>I have a server that is streaming json objects to an endpoint. Here is a simplified example:</p>
  
  <pre><code>app.get('/getJsonObjects', function (req, res) {
      res.write(JSON.stringify(json1));
      res.write(JSON.stringify(json2));
      res.write(JSON.stringify(json3));
      res.write(JSON.stringify(json4));
      res.write(JSON.stringify(json5));
      res.end();
  });
  </code></pre>
  
  <p>Then client side using browser-request, I'm trying to do:</p>
  
  <pre><code>var r = request(url);
  r.on('data', function(data) {
      console.log(JSON.parse(data));
  });
  </code></pre>
  
  <p>The problem is despite streaming to the endpoint chunks of valid stringified JSON, the chunks I'm getting back from the request are just text chunks that don't necessarily align with the start/end of the JSON chunks that were sent from the server. This means that JSON.parse(data) will sometimes fail.</p>
  
  <p>What is the best way to stream these chunks of json in the same way that they were written to the endpoint?</p>