dopplesoldner
dopplesoldner

Reputation: 9479

nodejs - How to deal with an API which returns circular structure JSON

I am using the Zoopla developer API to get some historical pricing data.

My http get method is as follows

http.get(url, function(err, data) {
  if (err) console.log(err);
  res.send(data);
});

I get TypeError: Converting circular structure to JSON when trying to use the above method.

Any ideas how to around this problem?

Upvotes: 0

Views: 2570

Answers (1)

alex
alex

Reputation: 12275

Second argument of http.get is not a data object. It's a response object.

You should do something like this instead:

http.get(url, function(err, response) {
  if (err) console.log(err)

  var data = ''
  response.setEncoding('utf8')
  response.on('data', function(d) {
    data += d
  })
  response.on('end', function(d) {
    res.send(data)
  })
})

Upvotes: 2

Related Questions