Parsing JSON in Shortcuts from an API request
If you look at the Dark Sky API response, you can see that there’s a lot of data stored in JSON. While it’s not easy to read at first, over time you’ll start to recognize the structures in JSON data, as well as how to identify dictionaries, lists, keys, and values. Often, developers include a nicely formatted version of the JSON data that their API will return, so look for that in their documentation. Additionally, it’s helpful to check your work using services like the online JSON Editor.
Notice that the top-level object is a dictionary with the keys latitude
, longitude
, timezone
, currently
, and minutely
. Some of these keys, such as latitude
and timezone
, simply contain a number or text value, but others, such as daily
, have a dictionary value.
And the daily
dictionary contains some keys with values that are simple text, such as the summary
, with Rain throughout the day
. But others, such as data
, are lists containing a forecast (represented by a dictionary) for each hour.