hi am parsing an api link at
https://api.nasa.gov/neo/rest/v1/feed?start_date=2019-09-07&end_date=2019-09-07&api_key=DEMO_KEY
I am trying to do a console.log for required column names such as (id and name)
This is what I have initially tried to do this
var http = require('https');
var url = 'https://api.nasa.gov/neo/rest/v1/feed?start_date=2019-09-07&end_date=2019-09-07&api_key=DEMO_KEY';
http.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var mars = JSON.parse(body);
console.log("Got a response: ", mars.near_earth_objects.name);
});
}).on('error', function(e){
console.log("Got an error: ", e);
});
But I keep getting an undefined error
but when I try to access the whole json from this
var http = require('https');
var url = 'https://api.nasa.gov/neo/rest/v1/feed?start_date=2019-09-07&end_date=2019-09-07&api_key=DEMO_KEY';
http.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var mars = JSON.parse(body);
console.log("Got a response: ", mars.near_earth_objects);
});
}).on('error', function(e){
console.log("Got an error: ", e);
});
I can see the name, id amongst the child nodes of the json result
Please how do I properly access the name and id column data