JSON Weather Patch Question

tomre's icon

Hey, i'm a total beginner in Max and I have a question regarding the JSON weather Patch that came with the Ableton Live Connection Kit:
How can I get more values (such as humidity, precipProbability, moonPhase, pressure and ozone) from the dictionary. temperature, windspeed, precipIntensity and cloudCover are working... every time i try with another value, i'm not getting a result. What am I missing?

tomre's icon

here's an example:
i am able to extract temperature, windSpeed, precipitationIntensity, and cloudCover in this patch, but not moonPhase. it's strange. does anybody know why?

weather fetcher.amxd
amxd 38.74 KB

Rob Ramirez's icon

if you look at the dictionary output from the marurl request, you can see that moonPhase is a key inside of of the body::daily::data subdictionary array. therefore in order to retrieve that you have to process the array of dictionaries in some way. JS is the preferred solution for this, turning the dictionary into a javascript object with something like the following : var jsob = JSON.parse(maxdict.stringify());

but you can process with max objects as well. the trick is to grab the dictionary name of whatever instance you are interested in, sending that to a dict object and then retrieving the key.

Max Patch
Copy patch and select New From Clipboard in Max.

tomre's icon

Great, thanks!!
But why doesn't it work for the "currently" array? Why does it seem to recognize temperature, windSpeed, cloudCover and precipitationIntensity only, and not others?

Rob Ramirez's icon

again, look at the data you are getting. there is no "moonPhase" entry in the "currently" sub-dict. it only appears in the "daily" sub-dict's "data" array.

tomre's icon

I know, what I meant was I did not figure out how to get other entries from the "currently" array. But I figured it out now - there is a subpatch (p query_Data) which specifies which elements can be read using a get:body message.

Vukasin Stancevic's icon

Hello ppl :)
I have a question, what I need achange in [zl.slice 1] to read 5th object in "body::daily::data" data array? Or maybe batter question is how can I read last article in data array?

Thank you!

Rob Ramirez's icon

it's just simple list processing to get the dictionary name that you are interested, either zl objects or unpack.
i think the easiest solution for this is to send the data array into an [ unpack s s s s s ]

Max Patch
Copy patch and select New From Clipboard in Max.

Vukasin Stancevic's icon

@rob Ramiez

Thank you so much!