Here is the situation:
I have a Rails app that scrapes a website and outputs valid JSON to a restful API endpoint.
So far I can get the JSON with my Node.js script, but I cannot store the values I need to local variables.
Here is the json:
[{"cohort":"1507","teacher":"Josh M."}]
I would like to store "1507"
in a variable as well as "Josh M."
My current script is:
var http = require('http');
var url = 'http://localhost:8080/api/v1/classroom_bs';
http.get(url, function(res){
var body = '';
res.on('data', function(chunk){
body += chunk;
});
res.on('end', function(){
var responseB = JSON.parse(body);
var responseBStr = JSON.stringify(body);
var jsonB = JSON.parse(responseBStr);
console.log(responseB);
console.log(responseBStr);
console.log(jsonB);
});
}).on('error', function(e){
console.log("Error: ", e);
});
Any help would be greatly appreciated!
I have tried some functions I found on SO, but for some reason all my console.log(Object.keys)
return numbers like "1"
, "2"
, "3"
, etc..
The reason I need to store these as variables is that I am going to output those values to an LCD screen using the johnny5 library via an Arduino.