Need simple example code:

Everything I say below is to the best of my understanding and I am probably using the wrong coding terminology, but I think it should help you understand how to get what you need going forward.

With the assistance of @ogiewon's great tool, it makes it a bit easier to see how to get what you want. Everything in the blue circle is listed under "features". Essentially "features" is an array that contains "title", "updated" and another subarray (circled in red) referenced at position "0".

Here's a couple of options to get you the feature/properties/id

log.debug response.data.features[0].properties.id

or

log.debug response.data.features[0]["properties"].id

image

Make sense?

2 Likes

This tool helped me a lot when developing the Logitech Harmony Hub webSockets based driver. I think I just got lucky in a Google search for “json viewer”.

1 Like

@stephack

You are awesome! Thank you for your guidance on this! It works!

2 Likes

I use this for generating selectors:

http://www.jsonquerytool.com/

1 Like

That's pretty nifty!

OK so now I know how to parse a single tree but....... what if I want to parse ALL the trees in 1 go ?

@ogiewon

You can take a look inside my Logitech Harmony Hub Parent Driver, as it iterates through json responses from the Harmony Hub to parse out the pieces it needs.

Here's a snippet of code that demonstrates iterating through json and pulling out the pieces I needed to take action on.

            json?.data?.activity?.each { it ->
                def tempID = (it.id == "-1") ? "PowerOff" : "${it.id}"                    
                if (logEnable) log.debug "Activity Label: ${it.label}, ID: ${tempID}"
                
                //store portion of config results in state veraible (needed for volume/channel control) 
                def volume = "null"
                if (it.roles?.VolumeActivityRole) volume = it.roles?.VolumeActivityRole
                def channel = "null"
                if (it.roles?.ChannelChangingActivityRole) channel = it.roles?.ChannelChangingActivityRole
                state.HarmonyConfig << ["id":"${it.id}", "label":"${it.label}", "VolumeActivityRole":"${volume}", "ChannelChangingActivityRole":"${channel}"]
                
                //Create a Child Switch Device for each Activity if needed, default all of them to 'off' for now
                updateChild(tempID, "unknown", it.label)
            }
1 Like

If you'd like an extreme example of json parsing look at echo speaks. It does some serious work.

1 Like

@aaron How did you go with getting this to work? I want to do something similar with our Australian Bureau of Meteorology that has a similar service where you send a http get and receive a JSON response. Here's an example URL for my home town. Thinking it'd be neat to access the current temp and play around with automation like closing our outdoor blinds if the temp is over a certain value or it's raining.

I created an entire app.

I will look at your given URL and see what is possible.

2 Likes

Thanks Aaron! That's brilliant! Thanks for having a look at it.

Good news - Australia has adopted the open standard CAP for weather alerts. SO there is a good possibility of creating a NOAA like application for AU citizens.

Bad news - all the documentation posted for CAP-AU does not contain the API URL to query and request weather alert data. I have sent an email of inquiry to see if I can acquire it from the AU meteorologist committee.

Keep you posted.