How can I iterate through a JSON file to retrieve the values of total
and first_record
? The specific key is:
json.STATION[0].OBSERVATIONS.precipitation[0].total
My goal is to display the result in the following format:
[20180116, 0.8], [20180117, 0.0] . . .
Despite trying different methods, I keep getting an output with undefined
as the best result. Below is a snippet from my work on JSFiddle where the JSON data is generated using the Mesowest.net API.
Once I resolve this issue, I intend to plot these values using Highcharts. Thank you for your help.
const data = {
"UNITS": {
"precipitation": "Inches"
},
"STATION": [{
"STATUS": "ACTIVE",
"MNET_ID": "25",
"PERIOD_OF_RECORD": {
"start": "20000120",
"end": "20180121"
},
"ELEVATION": "6340",
"NAME": "BOGUS BASIN",
"RESTRICTED": false,
"STID": "BOGI1",
"ELEV_DEM": "6362",
"LONGITUDE": "-116.09685",
"STATE": "ID",
"OBSERVATIONS": {
"precipitation": [{
"count": 23,
"first_report": "20180115",
"interval": 1,
"report_type": "precip_accum",
"last_report": "20180115",
"total": 0.0
}, {
"count": 24,
"first_report": "20180116",
"interval": 2,
"report_type": "precip_accum",
"last_report": "20180116",
"total": 0.2
}, {
"count": 24,
"first_report": "20180117",
"interval": 3,
"report_type": "precip_accum",
"last_report": "20180117",
"total": 0.0
}, {
"count": 24,
"first_report": "20180118",
"interval": 4,
"report_type": "precip_accum",
"last_report": "20180118",
"total": 0.0
}, {
"count": 24,
"first_report": "20180119",
"interval": 5,
"report_type": "precip_accum",
"last_report": "20180119",
"total": 0.8
}, {
"count": 24,...
<p id="demo"></p>