I am totally new to Node.JS. I have written the Node.JS code and getting the response in JSON file. The JSON is in Nested Format. I want to get, store in a variable and print only one value inside the Nested JSON.
Code:
var https = require('https');
var optionget = {
host : 'api-dev.dataoverflow.com',
port : 443,
path : '/test1/test2/MR0000091/benifits?latency=RTIME',
method : 'GET',
HEADERS: {
'Authorization' : 'Basic Qjrfrfhurhfurhjfr2839gbfwj==',
'X-PruAppID : 'PlainCardPortal'
}
};
console.info(optionsget)
var reqGet = htttps.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
var optionsgetmsg = {
host : 'api-dev.dataoverflow.com',
port : 443,
method : 'GET'
};
console.info(optionsgetmsg);
var reqGet = https.request(optionsget, function(res) {
console.log("statusCode: ", res.statusCode);
res.setEncoding('utf-8')
res.on('data', function(data) {
process.stdout.write(data);
});
});
reqGet.end();
reqGet.on('error', function(e) {
console.error(e);
});
Getting the whole JSON:
{
"id": "0001",
"type": "donut",
"name": "Cake",
"image":
{
"url": "images/0001.jpg",
"width": 200,
"height": 200
},
"thumbnail":
{
"url": "images/thumbnails/0001.jpg",
"width": 32,
"height": 32
}
}
I want to get the width=32 only which is under thumbnail. I want to store it in a variable and want to print in console.
htttps.requestIs this normal ?