I have been struggling to extract the specific contents of a JSON api without success. Despite my best efforts, the console always returns undefined. My goal is to retrieve and display only the Question object from the JSON data. After spending several hours attempting different methods and scouring through resources online, I am finally seeking guidance on how to solve this issue.
var url = 'https://opentdb.com/api.php?amount=1&category=15&type=multiple';
https.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var trivapi = JSON.parse(body);
console.log("Received response: ", trivapi[0].question);
});
}).on('error', function(e){
console.log("Encountered an error: ", e);
});