title: Unexpected End of JSON Input when pulling JSON from Reddit
body: <p>I am trying to pull some reddit posts from their json feed, as it is done in <a href="http://www.codingdefined.com/2015/12/get-latest-reddit-posts-in-nodejs.html" rel="nofollow noreferrer">this example</a>:</p>
  
  <pre><code>var http = require('http');
  
  
  function getRedditPosts() {
    var url = "http://www.reddit.com/r/jokes/new/.json?limit=1";
  
    var request = http.get(url, function(response) {
      var json = '';
      response.on('data', function(chunk) {
        json += chunk;
      });
  
      response.on('end', function() {
        var redditResponse = JSON.parse(json);
        redditResponse.data.children.forEach(function(child) {
      if(child.data.domain !== 'self.node') {
        console.log('-------------------------------');
        console.log('Author : ' + child.data.author);
        console.log('Domain : ' + child.data.domain);
        console.log('Title : ' + child.data.title);
        console.log('URL : ' + child.data.url);
      }
        });
      })
    });
    request.on('error', function(err) {
      console.log(err);
    });
  }
  
  getRedditPosts();
  </code></pre>
  
  <p>The problem is that I am getting a unexpected end of JSON input. Why is that?</p>
  
  <blockquote>
    <p>undefined:1</p>
    
    <p>SyntaxError: Unexpected end of JSON input
        at Object.parse (native)
        at IncomingMessage. (/Users/felix/Desktop/Dev/npmTest/index.js:14:33)
        at emitNone (events.js:91:20)
        at IncomingMessage.emit (events.js:185:7)
        at endReadableNT (_stream_readable.js:974:12)
        at _combinedTickCallback (internal/process/next_tick.js:74:11)
        at process._tickCallback (internal/process/next_tick.js:98:9)</p>
  </blockquote>