Parsing the response

The JSON object that is printed out by the console looks something like this (formatted for easier reading):

{
"coord":{"lon":-97.74,"lat":30.27},
"weather":[
{"id":800,"main":"Clear","description":"clear sky",
"icon":"01n"}
],
"base":"stations",
"main":{
"temp":305.59,
"pressure":1016,
"humidity":46,
"temp_min":304.15,
"temp_max":307.15
},
"visibility":16093,
"wind":{
"speed":3.6,
"deg":170,
"gust":8.2
},
"clouds":{"all":1},
"dt":1534470960,
"sys":{
"type":1,
"id":2558,
"message":0.0037,
"country":"US",
"sunrise":1534507156,
"sunset":1534554612
},
"id":4671654,
"name":"Austin",
"cod":200
}

That's a lot of weather data! Luckily, because the request npm module was passed the json: true property in the options, it assumes that anything passed back is JSON and parses it for you, so you can access data properties right away:

let longitude = body.coords.lon // -97.74
let conditions = weather.condition // 'clear sky'
let currentTemp = main.temp // 305.59 degrees Kelvin
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.151.45