Can someone provide a step-by-step on parsing JSON?

I have a project where I am parsing data from weather underground. (I'll post the example response I get from wunderground after this.)

What I am trying to figure out is how to pull out the hourly predicted precipitation for each of the next 10 hours from the response. This is all organized in a nested JSON response. There are many ways to skin the cat and I want to know the easiest (as in easiest to program and easiest to use).

  • I've seen a post here on the forum http://forum.arduino.cc//index.php?topic=192626.0 discussing the built in solutions: json.py, and jshn.sh. - I think the are built in anyway.
  • I also read a guest blog post about "The Yún Way: less time debugging and more time inventing" http://blog.arduino.cc/2013/09/23/the-yun-way/ In this blog post, Sven Kräuter says that "...although there’s much debate when it comes to JSON processing with regular expressions in general, I just used grep and a matching regexp to extract the information from Foursquare’s JSON response."
  • I read about another console tool called jq here http://grep.codeconsult.ch/2013/09/26/jq-sed-grep-and-awk-for-json/ "As the tagline says, jq is like sed, grep and awk for json: a command-line filter that lets you format, select and output JSON data."

I like built in solutions because I don't know how to hack around the linino installation to add new scripts. Can someone step me through how to use either json.py or jshn.sh to pull [date/time] and [QPF] for each hour in the future into a matrix or even individual variables?

After reading up on regex and grep, I learned that many people don't recommend mixing regular expressions and JSON. As such, unless someone suggests otherwise, I plan to avoid using grep.

What is interesting about the jq tool is that the examples http://stedolan.github.io/jq/tutorial/ seem pretty straightforward (and it allows you to use regular expressions). This is not built in but if (1) a console tool can be called and used from the arduino bridge, (2) someone can show me how to install this and (3) he/she thinks it is better than jshn or json.py, then I would be much obliged.

The following post is the response I get from weather underground....

I am pulling the following items out of the response for each hour included in the repsonse. "hourly_forecast": [ { "FCTTIME": { ....I just want the "hour" and "epoch" * }, *"qpf"*: *....I just want this in english }

Here is an example response (shortened, normal response includes 10 hours). Can anybody step me through this? Thank you so much.

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "hourly": 1
  }
    }
        ,
    "hourly_forecast": [
        {
        "FCTTIME": {
        "hour": "23","hour_padded": "23","min": "00","sec": "0","year": "2013","mon": "10","mon_padded": "10","mon_abbrev": "Oct","mday": "22","mday_padded": "22","yday": "294","isdst": "1","epoch": "1382497200","pretty": "11:00 PM EDT on October 22, 2013","civil": "11:00 PM","month_name": "October","month_name_abbrev": "Oct","weekday_name": "Tuesday","weekday_name_night": "Tuesday Night","weekday_name_abbrev": "Tue","weekday_name_unlang": "Tuesday","weekday_name_night_unlang": "Tuesday Night","ampm": "PM","tz": "","age": ""
        },
        "temp": {"english": "48", "metric": "9"},
        "dewpoint": {"english": "34", "metric": "1"},
        "condition": "Chance of Rain",
        "icon": "chancerain",
        "icon_url":"http://icons-ak.wxug.com/i/c/k/nt_chancerain.gif",
        "fctcode": "12",
        "sky": "86",
        "wspd": {"english": "2", "metric": "3"},
        "wdir": {"dir": "NE", "degrees": "45"},
        "wx": "Chance of Light Rain",
        "uvi": "0",
        "humidity": "56",
        "windchill": {"english": "-9998", "metric": "-9998"},
        "heatindex": {"english": "-9998", "metric": "-9998"},
        "feelslike": {"english": "48", "metric": "9"},
        "qpf": {"english": "0.01", "metric": "0.25"},
        "snow": {"english": "", "metric": ""},
        "pop": "100",
        "mslp": {"english": "29.86", "metric": "1011"}
        }
        ,
        {
        "FCTTIME": {
        "hour": "0","hour_padded": "00","min": "00","sec": "0","year": "2013","mon": "10","mon_padded": "10","mon_abbrev": "Oct","mday": "23","mday_padded": "23","yday": "295","isdst": "1","epoch": "1382500800","pretty": "12:00 AM EDT on October 23, 2013","civil": "12:00 AM","month_name": "October","month_name_abbrev": "Oct","weekday_name": "Wednesday","weekday_name_night": "Wednesday Night","weekday_name_abbrev": "Wed","weekday_name_unlang": "Wednesday","weekday_name_night_unlang": "Wednesday Night","ampm": "AM","tz": "","age": ""
        },
        "temp": {"english": "46", "metric": "8"},
        "dewpoint": {"english": "35", "metric": "1"},
        "condition": "Chance of Rain",
        "icon": "chancerain",
        "icon_url":"http://icons-ak.wxug.com/i/c/k/nt_chancerain.gif",
        "fctcode": "12",
        "sky": "86",
        "wspd": {"english": "2", "metric": "4"},
        "wdir": {"dir": "NE", "degrees": "45"},
        "wx": "Chance of Light Rain",
        "uvi": "0",
        "humidity": "64",
        "windchill": {"english": "-9998", "metric": "-9998"},
        "heatindex": {"english": "-9998", "metric": "-9998"},
        "feelslike": {"english": "46", "metric": "8"},
        "qpf": {"english": "", "metric": ""},
        "snow": {"english": "", "metric": ""},
        "pop": "100",
        "mslp": {"english": "29.86", "metric": "1011"}
        }
        ,
        {
        "FCTTIME": {
        "hour": "1","hour_padded": "01","min": "00","sec": "0","year": "2013","mon": "10","mon_padded": "10","mon_abbrev": "Oct","mday": "23","mday_padded": "23","yday": "295","isdst": "1","epoch": "1382504400","pretty": "1:00 AM EDT on October 23, 2013","civil": "1:00 AM","month_name": "October","month_name_abbrev": "Oct","weekday_name": "Wednesday","weekday_name_night": "Wednesday Night","weekday_name_abbrev": "Wed","weekday_name_unlang": "Wednesday","weekday_name_night_unlang": "Wednesday Night","ampm": "AM","tz": "","age": ""
        },
        "temp": {"english": "45", "metric": "7"},
        "dewpoint": {"english": "35", "metric": "2"},
        "condition": "Chance of Rain",
        "icon": "chancerain",
        "icon_url":"http://icons-ak.wxug.com/i/c/k/nt_chancerain.gif",
        "fctcode": "12",
        "sky": "86",
        "wspd": {"english": "3", "metric": "4"},
        "wdir": {"dir": "NE", "degrees": "45"},
        "wx": "Chance of Light Rain",
        "uvi": "0",
        "humidity": "71",
        "windchill": {"english": "-9998", "metric": "-9998"},
        "heatindex": {"english": "-9998", "metric": "-9998"},
        "feelslike": {"english": "45", "metric": "7"},
        "qpf": {"english": "", "metric": ""},
        "snow": {"english": "", "metric": ""},
        "pop": "100",
        "mslp": {"english": "29.86", "metric": "1011"}
        }
        ,
        {
        "FCTTIME": {
        "hour": "2","hour_padded": "02","min": "00","sec": "0","year": "2013","mon": "10","mon_padded": "10","mon_abbrev": "Oct","mday": "23","mday_padded": "23","yday": "295","isdst": "1","epoch": "1382508000","pretty": "2:00 AM EDT on October 23, 2013","civil": "2:00 AM","month_name": "October","month_name_abbrev": "Oct","weekday_name": "Wednesday","weekday_name_night": "Wednesday Night","weekday_name_abbrev": "Wed","weekday_name_unlang": "Wednesday","weekday_name_night_unlang": "Wednesday Night","ampm": "AM","tz": "","age": ""
        },
        "temp": {"english": "43", "metric": "6"},
        "dewpoint": {"english": "36", "metric": "2"},
        "condition": "Rain",
        "icon": "rain",
        "icon_url":"http://icons-ak.wxug.com/i/c/k/nt_rain.gif",
        "fctcode": "13",
        "sky": "97",
        "wspd": {"english": "3", "metric": "5"},
        "wdir": {"dir": "East", "degrees": "99"},
        "wx": "Definite Light Rain",
        "uvi": "0",
        "humidity": "79",
        "windchill": {"english": "-9998", "metric": "-9998"},
        "heatindex": {"english": "-9998", "metric": "-9998"},
        "feelslike": {"english": "43", "metric": "6"},
        "qpf": {"english": "0.01", "metric": "0.25"},
        "snow": {"english": "0.00", "metric": "0.00"},
        "pop": "100",
        "mslp": {"english": "29.82", "metric": "1009"}
        }
    ]
}

I'd go with python: it's already installed and if you google for JSON python example you'll find a lot of links, this one in particular looks like it has everything you need

I'd avoid grep whenever possible: it's great tool that I love using with log files but json API responses need a proper json parser

Have you tested the library aJson?

info: http://hardwarefun.com/tutorials/parsing-json-in-arduino