AnsweredAssumed Answered

parsing JSON weather data

Question asked by alekz on Jun 17, 2015
Latest reply on Jun 17, 2015 by SteveMartino

Title

parsing JSON weather data

Post

My goal is to retrieve a 10-day forecast using the Wunderground API and parse it into a table with 10 records. I want to update the same 10 records on a daily basis with fresh forecast data. I don't need the 19 day forecast that comes first. I want just a few data points from the second part of the detailed 10 day forecast such as low/high temp and humidity for the day. I picked JSON but XML output is also available.

I'm looking at sample code provided at the website below here but it's difficult to reinterpret it for my needs.
http://www.soliantconsulting.com/blog/2011/12/how-to-parse-json-or-any-other-language-in-filemaker

Is there a better way of parsing this data?
Should I just keep working with the above script example until I get it?
Would XML be better?

Here's the data that I get with the "Insert from URL" script step:


{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "forecast10day": 1
  }
    }
        ,
    "forecast":{
        "txt_forecast": {
        "date":"4:03 PM EDT",
        "forecastday": [
        {
        "period":0,
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "title":"Tuesday",
        "fcttext":"A few clouds. Lows overnight in the mid 70s.",
        "fcttext_metric":"Mostly clear. Low 24C.",
        "pop":"0"
        }
        ,

//(repeating code omitted for periods 1-18)
     
        {
        "period":19,
        "icon":"nt_chancetstorms",
        "icon_url":"http://icons.wxug.com/i/c/k/nt_chancetstorms.gif",
        "title":"Thursday Night",
        "fcttext":"Scattered thunderstorms. Low around 75F. Winds light and variable. Chance of rain 50%.",
        "fcttext_metric":"Variable clouds with scattered thunderstorms. Low 24C. Winds light and variable. Chance of rain 50%.",
        "pop":"50"
        }
        ]
        },
        "simpleforecast": {
        "forecastday": [
        {"date":{
    "epoch":"1434495600",
    "pretty":"7:00 PM EDT on June 16, 2015",
    "day":16,
    "month":6,
    "year":2015,
    "yday":166,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"June",
    "monthname_short":"Jun",
    "weekday_short":"Tue",
    "weekday":"Tuesday",
    "ampm":"PM",
    "tz_short":"EDT",
    "tz_long":"America/New_York"
},
        "period":1,
        "high": {
        "fahrenheit":"102",
        "celsius":"38"
        },
        "low": {
        "fahrenheit":"74",
        "celsius":"23"
        },
        "conditions":"Clear",
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "skyicon":"",
        "pop":0,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": null,
        "mm": null
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": null,
        "cm": null
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 7,
        "kph": 11,
        "dir": "",
        "degrees": 0
        },
        "avewind": {
        "mph": 0,
        "kph": 0,
        "dir": "West",
        "degrees": 270
        },
        "avehumidity": 67,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,


//(repeating code omitted for periods 2-9)
        
        {"date":{
    "epoch":"1435273200",
    "pretty":"7:00 PM EDT on June 25, 2015",
    "day":25,
    "month":6,
    "year":2015,
    "yday":175,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"June",
    "monthname_short":"Jun",
    "weekday_short":"Thu",
    "weekday":"Thursday",
    "ampm":"PM",
    "tz_short":"EDT",
    "tz_long":"America/New_York"
},
        "period":10,
        "high": {
        "fahrenheit":"97",
        "celsius":"36"
        },
        "low": {
        "fahrenheit":"75",
        "celsius":"24"
        },
        "conditions":"Chance of a Thunderstorm",
        "icon":"chancetstorms",
        "icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
        "skyicon":"",
        "pop":50,
        "qpf_allday": {
        "in": 0.20,
        "mm": 5
        },
        "qpf_day": {
        "in": 0.07,
        "mm": 2
        },
        "qpf_night": {
        "in": 0.13,
        "mm": 3
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 10,
        "kph": 16,
        "dir": "W",
        "degrees": 274
        },
        "avewind": {
        "mph": 6,
        "kph": 10,
        "dir": "W",
        "degrees": 274
        },
        "avehumidity": 51,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ]
        }
    }
}

 

Outcomes