Need simple example code:

Hello all,

I am attempting to shake off the thick rust on my development skills. Ok..I am a hack but I really want to contribute. :slight_smile:

I am in need of assistance. I am looking for a simple example that I could reference that does the following:

  1. Makes an HTTP GET request to an URL to acquire a json feed ( https://api.weather.gov/alerts/active?status=exercise&message_type=alert&point=)
  2. Parse the feed and place information from feed into string variables

I apologize about being such a n00bie on this but having this understanding will help me greatly.

Take a look at

1 Like

@aaron
Have a look at any of the custom weather drivers.
they all make a get request and parse the result into different string variables to send as attributes.

Andy

1 Like
	def wxURI = "https://api.weather.gov/alerts/active?status=exercise&message_type=alert&point=41.540583%2C-88.276465"

	def requestParams =
	[
		uri:  wxURI,
		requestContentType: "application/json"
	]

	httpGet(requestParams)
	{
	  response ->
		if (response?.status == 200)
		{
			return response.data
		}
		else
		{
			log.warn "${response?.status}"
		}
	}

This should fetch the data and return it as a map. What you do with it after, is up to you. :slight_smile:

2 Likes

The Pushover driver also has a simple example of this in the getSoundOptions() method.

When you do an httpGet, the returned info is stored in the "response" object (more specifically in the "response.data").

The first thing I would do is output the contents of response.data to your logs so you view what is being returned. That will tell you what you need to do to parse the results.

https://github.com/ogiewon/Hubitat/blob/master/Drivers/pushover-notifications.src/pushover-notifications.groovy

1 Like

So within the response.data how would I go about acquiring the fields inside the json results? Again learning so I appreciate the assistance.

So for this URL: https://api.weather.gov/alerts/active?status=actual&point=41.540583%2C-88.276465

I receive the following JSON response:

{
    "@context": [
        "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
        {
            "wx": "https://api.weather.gov/ontology#",
            "@vocab": "https://api.weather.gov/ontology#"
        }
    ],
    "type": "FeatureCollection",
    "features": [
        {
            "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502",
            "type": "Feature",
            "geometry": null,
            "properties": {
                "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502",
                "@type": "wx:Alert",
                "id": "NWS-IDP-PROD-3381285-2960502",
                "areaDesc": "Lake; Kendall; Porter; Will; Grundy",
                "geocode": {
                    "UGC": [
                        "INZ001",
                        "ILZ020",
                        "INZ002",
                        "ILZ022",
                        "ILZ021"
                    ],
                    "SAME": [
                        "018089",
                        "017093",
                        "018127",
                        "017197",
                        "017063"
                    ]
                },
                "affectedZones": [
                    "https://api.weather.gov/zones/forecast/INZ001",
                    "https://api.weather.gov/zones/forecast/ILZ020",
                    "https://api.weather.gov/zones/forecast/INZ002",
                    "https://api.weather.gov/zones/forecast/ILZ022",
                    "https://api.weather.gov/zones/forecast/ILZ021"
                ],
                "references": [
                    {
                        "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3380703-2959958",
                        "identifier": "NWS-IDP-PROD-3380703-2959958",
                        "sender": "w-nws.webmaster@noaa.gov",
                        "sent": "2019-02-19T03:35:00-06:00"
                    }
                ],
                "sent": "2019-02-19T11:01:00-06:00",
                "effective": "2019-02-19T11:01:00-06:00",
                "onset": "2019-02-20T03:00:00-06:00",
                "expires": "2019-02-19T19:15:00-06:00",
                "ends": "2019-02-20T12:00:00-06:00",
                "status": "Actual",
                "messageType": "Update",
                "category": "Met",
                "severity": "Moderate",
                "certainty": "Likely",
                "urgency": "Expected",
                "event": "Winter Weather Advisory",
                "sender": "w-nws.webmaster@noaa.gov",
                "senderName": "NWS Chicago IL",
                "headline": "Winter Weather Advisory issued February 19 at 11:01AM CST expiring February 20 at 12:00PM CST by NWS Chicago IL",
                "description": "* WHAT...Mixed precipitation expected. Total snow accumulations\nof up to one inch and ice accumulations of a few hundredths\nleading to at least a light glaze expected.\n\n* WHERE...In Indiana, Lake IN and Porter Counties. In Illinois,\nKendall, Grundy and Will Counties.\n\n* WHEN...From 3 AM to noon CST Wednesday.\n\n* ADDITIONAL DETAILS...Plan on slippery road conditions. The\nhazardous conditions could impact the morning commute.",
                "instruction": "A Winter Weather Advisory means that periods of snow, sleet or\nfreezing rain will cause travel difficulties. Expect slippery\nroads and limited visibilities, and use caution while driving.\n\nThe latest road conditions can be obtained by going to\nwww.gettingaroundillinois.com in Illinois or by calling\n1 8 0 0 2 6 1 7 6 2 3 in Indiana.",
                "response": "Execute",
                "parameters": {
                    "NWSheadline": [
                        "WINTER WEATHER ADVISORY REMAINS IN EFFECT FROM 3 AM TO NOON CST WEDNESDAY"
                    ],
                    "HazardType": [
                        "Mixed Precipitation"
                    ],
                    "VTEC": [
                        "/O.CON.KLOT.WW.Y.0014.190220T0900Z-190220T1800Z/"
                    ],
                    "PIL": [
                        "LOTWSWLOT"
                    ],
                    "BLOCKCHANNEL": [
                        "CMAS",
                        "EAS",
                        "NWEM"
                    ],
                    "eventEndingTime": [
                        "2019-02-20T12:00:00-06:00"
                    ]
                }
            }
        }
    ],
    "title": "current watches, warnings, and advisories for 41.540583 N, 88.276465 W",
    "updated": "2019-02-19T19:37:21+00:00"
}

So how would I associate data from the response.data into individual fields?

Would it be something like below?

countiesaffected = response.data(features.properties.areaDesc)
TimePosted = response.data(features.properties.sent)
Message = response.data(features.properties.description)

I don't code for a living and there are often nuances to how you parse json (or json-like data)....but you are very close.
It would likely be closer to:

def countiesaffected = response.data.features.properties.areaDesc
def timePosted = response.data.features.properties.sent
def message = response.data.features.properties.description

Remember, log output is your friend. If you don't get the expected result..output a log each step of the way.
log.info response.data
log.info response.data.features
log.info response.data.features.properties
etc

2 Likes

Ok so here is the device code I created to test:

import groovy.json.*
	
	metadata {
	definition (name: "NOAA Weather Alerts", namespace: "aaronward", author: "Aaron Ward") {
		capability "Refresh"
	}
	preferences {
		section {
			input (
				type: "bool",
				name: "enableDebugLogging",
				title: "Enable Debug Logging?",
				required: true,
				defaultValue: true
			)
		}
	}
}

def log(msg) {
	if (enableDebugLogging) {
		log.debug(msg)	
	}
}

def installed () {
	log.info "${device.displayName}.installed()"
    updated()
}

def updated () {
	log.info "${device.displayName}.updated()"
    runIn(5, refresh)				// But test it once, right after we install or update it too.
}

def refresh() {
		def wxURI = "https://api.weather.gov/alerts/active?status=actual&point=41.540583%2C-88.276465"

	def requestParams =
	[
		uri:  wxURI,
		requestContentType: "application/geo+json"
	]

	httpGet(requestParams)
	{
	  response ->
		if (response?.status == 200)
		{
			log.info response.data.features.properties.areaDesc
			log.info response.data.features.properties.sent
			log.info response.data.features.properties.description
		}
		else
		{
			log.warn "${response?.status}"
		}
	}

}

But I get this error:
dev:19032019-02-19 02:28:44.977 pm errorgroovy.lang.MissingPropertyException: No such property: features for class: java.io.ByteArrayInputStream on line 50 (refresh)

Try changing this to
requestContentType: "application/json"

Same error. :frowning:

Here is the logs I am getting:

dev:19032019-02-19 02:51:21.081 pm errorgroovy.lang.MissingPropertyException: No such property: features for class: java.io.ByteArrayInputStream on line 53 (refresh)
dev:19032019-02-19 02:51:21.025 pm inforesponse data: {
    "@context": [
        "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld",
        {
            "wx": "https://api.weather.gov/ontology#",
            "@vocab": "https://api.weather.gov/ontology#"
        }
    ],
    "type": "FeatureCollection",
    "features": [
        {
            "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502",
            "type": "Feature",
            "geometry": null,
            "properties": {
                "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502",
                "@type": "wx:Alert",
                "id": "NWS-IDP-PROD-3381285-2960502",
                "areaDesc": "Lake; Kendall; Porter; Will; Grundy",
                "geocode": {
                    "UGC": [
                        "INZ001",
                        "ILZ020",
                        "INZ002",
                        "ILZ022",
                        "ILZ021"
                    ],
                    "SAME": [
                        "018089",
                        "017093",
                        "018127",
                        "017197",
                        "017063"
                    ]
                },
                "affectedZones": [
                    "https://api.weather.gov/zones/forecast/INZ001",
                    "https://api.weather.gov/zones/forecast/ILZ020",
                    "https://api.weather.gov/zones/forecast/INZ002",
                    "https://api.weather.gov/zones/forecast/ILZ022",
                    "https://api.weather.gov/zones/forecast/ILZ021"
                ],
                "references": [
                    {
                        "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-3380703-2959958",
                        "identifier": "NWS-IDP-PROD-3380703-2959958",
                        "sender": "w-nws.webmaster@noaa.gov",
                        "sent": "2019-02-19T03:35:00-06:00"
                    }
                ],
                "sent": "2019-02-19T11:01:00-06:00",
                "effective": "2019-02-19T11:01:00-06:00",
                "onset": "2019-02-20T03:00:00-06:00",
                "expires": "2019-02-19T19:15:00-06:00",
                "ends": "2019-02-20T12:00:00-06:00",
                "status": "Actual",
                "messageType": "Update",
                "category": "Met",
                "severity": "Moderate",
                "certainty": "Likely",
                "urgency": "Expected",
                "event": "Winter Weather Advisory",
                "sender": "w-nws.webmaster@noaa.gov",
                "senderName": "NWS Chicago IL",
                "headline": "Winter Weather Advisory issued February 19 at 11:01AM CST expiring February 20 at 12:00PM CST by NWS Chicago IL",
                "description": "* WHAT...Mixed precipitation expected. Total snow accumulations\nof up to one inch and ice accumulations of a few hundredths\nleading to at least a light glaze expected.\n\n* WHERE...In Indiana, Lake IN and Porter Counties. In Illinois,\nKendall, Grundy and Will Counties.\n\n* WHEN...From 3 AM to noon CST Wednesday.\n\n* ADDITIONAL DETAILS...Plan on slippery road conditions. The\nhazardous conditions could impact the morning commute.",
                "instruction": "A Winter Weather Advisory means that periods of snow, sleet or\nfreezing rain will cause travel difficulties. Expect slippery\nroads and limited visibilities, and use caution while driving.\n\nThe latest road conditions can be obtained by going to\nwww.gettingaroundillinois.com in Illinois or by calling\n1 8 0 0 2 6 1 7 6 2 3 in Indiana.",
                "response": "Execute",
                "parameters": {
                    "NWSheadline": [
                        "WINTER WEATHER ADVISORY REMAINS IN EFFECT FROM 3 AM TO NOON CST WEDNESDAY"
                    ],
                    "HazardType": [
                        "Mixed Precipitation"
                    ],
                    "VTEC": [
                        "/O.CON.KLOT.WW.Y.0014.190220T0900Z-190220T1800Z/"
                    ],
                    "PIL": [
                        "LOTWSWLOT"
                    ],
                    "BLOCKCHANNEL": [
                        "CMAS",
                        "EAS",
                        "NWEM"
                    ],
                    "eventEndingTime": [
                        "2019-02-20T12:00:00-06:00"
                    ]
                }
            }
        }
    ],
    "title": "current watches, warnings, and advisories for 41.540583 N, 88.276465 W",
    "updated": "2019-02-19T20:50:38+00:00"
}
dev:19032019-02-19 02:51:20.922 pm inforesponse contentType: application/geo+json
dev:19032019-02-19 02:51:20.920 pm infoparams2: [uri:https://api.weather.gov/alerts/active?status=actual&point=41.540583%2C-88.276465, requestContentType:application/json]
dev:19032019-02-19 02:51:20.917 pm infoResponse2: Strict-Transport-Security : max-age=31536000 ; includeSubDomains ; preload
dev:19032019-02-19 02:51:20.915 pm infoResponse2: Vary : Accept
dev:19032019-02-19 02:51:20.913 pm infoResponse2: Vary : Accept-Encoding
dev:19032019-02-19 02:51:20.910 pm infoResponse2: Connection : keep-alive
dev:19032019-02-19 02:51:20.908 pm infoResponse2: Date : Tue, 19 Feb 2019 20:51:20 GMT
dev:19032019-02-19 02:51:20.905 pm infoResponse2: Expires : Tue, 19 Feb 2019 20:51:50 GMT
dev:19032019-02-19 02:51:20.903 pm infoResponse2: Cache-Control : public, max-age=30, s-maxage=30
dev:19032019-02-19 02:51:20.897 pm infoResponse2: X-Request-ID : 2766a939-5809-44f3-ae33-5c7ca71198c8
dev:19032019-02-19 02:51:20.895 pm infoResponse2: X-Correlation-ID : 2766a939-5809-44f3-ae33-5c7ca71198c8
dev:19032019-02-19 02:51:20.893 pm infoResponse2: X-Server-ID : vm-lnx-nids-apiapp37.ncep.noaa.gov
dev:19032019-02-19 02:51:20.891 pm infoResponse2: Access-Control-Allow-Origin : *
dev:19032019-02-19 02:51:20.889 pm infoResponse2: Last-Modified : Tue, 19 Feb 2019 20:50:38 GMT
dev:19032019-02-19 02:51:20.887 pm infoResponse2: Content-Type : application/geo+json
dev:19032019-02-19 02:51:20.885 pm infoResponse2: Server : nginx/1.12.2

I like to use this website to make it easier to view JSON in a tree view.

http://jsonviewer.stack.hu/

For example, your JSON looks like the following in tree view.

This allows me to focus on the specific values that I care about and can ignore the rest.

1 Like

Great find btw!

So based on this I believe I should be able to see data from response.data.features.properties.sent but I still keep getting the error. This is where I get stuck most times attempting to get the data. Once I can get the data I can be fairly proficient in coding the logic.

I would try changing your code as follows:

def requestParams =
[
	uri:  wxURI,
	requestContentType: "application/json",
	contentType: "application/json"
]

EDIT: Added missing comma above.

Well that did something interesting. I now do not have the error but it is null for the response. I copied the response.data that is in the logs and attempted to place into your online JSON viewer tool you introduced me to but now it is not formatted JSON.

Here is my logging output:

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.599 pm [info](http://10.0.2.38/device/edit/1903)type: null

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.597 pm [info](http://10.0.2.38/device/edit/1903)response data: [@context:[https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld, [wx:https://api.weather.gov/ontology#, @vocab:https://api.weather.gov/ontology#]], type:FeatureCollection, features:[[id:https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502, type:Feature, geometry:null, properties:[@id:https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502, @type:wx:Alert, id:NWS-IDP-PROD-3381285-2960502, areaDesc:Lake; Kendall; Porter; Will; Grundy, geocode:[UGC:[INZ001, ILZ020, INZ002, ILZ022, ILZ021], SAME:[018089, 017093, 018127, 017197, 017063]], affectedZones:[https://api.weather.gov/zones/forecast/INZ001, https://api.weather.gov/zones/forecast/ILZ020, https://api.weather.gov/zones/forecast/INZ002, https://api.weather.gov/zones/forecast/ILZ022, https://api.weather.gov/zones/forecast/ILZ021], references:[[@id:https://api.weather.gov/alerts/NWS-IDP-PROD-3380703-2959958, identifier:NWS-IDP-PROD-3380703-2959958, sender:w-nws.webmaster@noaa.gov, sent:2019-02-19T03:35:00-06:00]], sent:2019-02-19T11:01:00-06:00, effective:2019-02-19T11:01:00-06:00, onset:2019-02-20T03:00:00-06:00, expires:2019-02-19T19:15:00-06:00, ends:2019-02-20T12:00:00-06:00, status:Actual, messageType:Update, category:Met, severity:Moderate, certainty:Likely, urgency:Expected, event:Winter Weather Advisory, sender:w-nws.webmaster@noaa.gov, senderName:NWS Chicago IL, headline:Winter Weather Advisory issued February 19 at 11:01AM CST expiring February 20 at 12:00PM CST by NWS Chicago IL, description:* WHAT...Mixed precipitation expected. Total snow accumulations of up to one inch and ice accumulations of a few hundredths leading to at least a light glaze expected. * WHERE...In Indiana, Lake IN and Porter Counties. In Illinois, Kendall, Grundy and Will Counties. * WHEN...From 3 AM to noon CST Wednesday. * ADDITIONAL DETAILS...Plan on slippery road conditions. The hazardous conditions could impact the morning commute., instruction:A Winter Weather Advisory means that periods of snow, sleet or freezing rain will cause travel difficulties. Expect slippery roads and limited visibilities, and use caution while driving. The latest road conditions can be obtained by going to www.gettingaroundillinois.com in Illinois or by calling 1 8 0 0 2 6 1 7 6 2 3 in Indiana., response:Execute, parameters:[NWSheadline:[WINTER WEATHER ADVISORY REMAINS IN EFFECT FROM 3 AM TO NOON CST WEDNESDAY], HazardType:[Mixed Precipitation], VTEC:[/O.CON.KLOT.WW.Y.0014.190220T0900Z-190220T1800Z/], PIL:[LOTWSWLOT], BLOCKCHANNEL:[CMAS, EAS, NWEM], eventEndingTime:[2019-02-20T12:00:00-06:00]]]]], title:current watches, warnings, and advisories for 41.540583 N, 88.276465 W, updated:2019-02-19T11:15:00-10:00]

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.528 pm [info](http://10.0.2.38/device/edit/1903)response contentType: application/geo+json

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.527 pm [info](http://10.0.2.38/device/edit/1903)params2: [uri:https://api.weather.gov/alerts/active?status=actual&point=41.540583%2C-88.276465, requestContentType:application/json, contentType:application/json]

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.525 pm [info](http://10.0.2.38/device/edit/1903)Response2: Strict-Transport-Security : max-age=31536000 ; includeSubDomains ; preload

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.523 pm [info](http://10.0.2.38/device/edit/1903)Response2: Vary : Accept

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.521 pm [info](http://10.0.2.38/device/edit/1903)Response2: Vary : Accept-Encoding

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.519 pm [info](http://10.0.2.38/device/edit/1903)Response2: Connection : keep-alive

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.518 pm [info](http://10.0.2.38/device/edit/1903)Response2: Date : Tue, 19 Feb 2019 21:16:10 GMT

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.516 pm [info](http://10.0.2.38/device/edit/1903)Response2: Expires : Tue, 19 Feb 2019 21:16:40 GMT

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.514 pm [info](http://10.0.2.38/device/edit/1903)Response2: Cache-Control : public, max-age=30, s-maxage=30

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.512 pm [info](http://10.0.2.38/device/edit/1903)Response2: X-Request-ID : 7327f7fc-6b94-498e-8b90-3e90dc3d2b05

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.509 pm [info](http://10.0.2.38/device/edit/1903)Response2: X-Correlation-ID : 7327f7fc-6b94-498e-8b90-3e90dc3d2b05

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.506 pm [info](http://10.0.2.38/device/edit/1903)Response2: X-Server-ID : vm-lnx-nids-apiapp10.ncep.noaa.gov

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.503 pm [info](http://10.0.2.38/device/edit/1903)Response2: Access-Control-Allow-Origin : *

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.500 pm [info](http://10.0.2.38/device/edit/1903)Response2: Last-Modified : Tue, 19 Feb 2019 21:15:00 GMT

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.496 pm [info](http://10.0.2.38/device/edit/1903)Response2: Content-Type : application/geo+json

[dev:1903](http://10.0.2.38/logs#dev1903)2019-02-19 03:16:10.493 pm [info](http://10.0.2.38/device/edit/1903)Response2: Server : nginx/1.12.2

Response.data
[@context:[https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld, [wx:https://api.weather.gov/ontology#, @vocab:https://api.weather.gov/ontology#]], type:FeatureCollection, features:[[id:https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502, type:Feature, geometry:null, properties:[@id:https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502, @type:wx:Alert, id:NWS-IDP-PROD-3381285-2960502, areaDesc:Lake; Kendall; Porter; Will; Grundy, geocode:[UGC:[INZ001, ILZ020, INZ002, ILZ022, ILZ021], SAME:[018089, 017093, 018127, 017197, 017063]], affectedZones:[https://api.weather.gov/zones/forecast/INZ001, https://api.weather.gov/zones/forecast/ILZ020, https://api.weather.gov/zones/forecast/INZ002, https://api.weather.gov/zones/forecast/ILZ022, https://api.weather.gov/zones/forecast/ILZ021], references:[[@id:https://api.weather.gov/alerts/NWS-IDP-PROD-3380703-2959958, identifier:NWS-IDP-PROD-3380703-2959958, sender:w-nws.webmaster@noaa.gov, sent:2019-02-19T03:35:00-06:00]], sent:2019-02-19T11:01:00-06:00, effective:2019-02-19T11:01:00-06:00, onset:2019-02-20T03:00:00-06:00, expires:2019-02-19T19:15:00-06:00, ends:2019-02-20T12:00:00-06:00, status:Actual, messageType:Update, category:Met, severity:Moderate, certainty:Likely, urgency:Expected, event:Winter Weather Advisory, sender:w-nws.webmaster@noaa.gov, senderName:NWS Chicago IL, headline:Winter Weather Advisory issued February 19 at 11:01AM CST expiring February 20 at 12:00PM CST by NWS Chicago IL, description:* WHAT...Mixed precipitation expected. Total snow accumulations
of up to one inch and ice accumulations of a few hundredths
leading to at least a light glaze expected.

* WHERE...In Indiana, Lake IN and Porter Counties. In Illinois,
Kendall, Grundy and Will Counties.

* WHEN...From 3 AM to noon CST Wednesday.

* ADDITIONAL DETAILS...Plan on slippery road conditions. The
hazardous conditions could impact the morning commute., instruction:A Winter Weather Advisory means that periods of snow, sleet or
freezing rain will cause travel difficulties. Expect slippery
roads and limited visibilities, and use caution while driving.

The latest road conditions can be obtained by going to
www.gettingaroundillinois.com in Illinois or by calling
1 8 0 0 2 6 1 7 6 2 3 in Indiana., response:Execute, parameters:[NWSheadline:[WINTER WEATHER ADVISORY REMAINS IN EFFECT FROM 3 AM TO NOON CST WEDNESDAY], HazardType:[Mixed Precipitation], VTEC:[/O.CON.KLOT.WW.Y.0014.190220T0900Z-190220T1800Z/], PIL:[LOTWSWLOT], BLOCKCHANNEL:[CMAS, EAS, NWEM], eventEndingTime:[2019-02-20T12:00:00-06:00]]]]], title:current watches, warnings, and advisories for 41.540583 N, 88.276465 W, updated:2019-02-19T11:15:00-10:00]

@aaron, you may have a typo somewhee in your code.
I loaded your driver with @ogiewon suggested change and Iwas able to do an initial parse. See full code below

import groovy.json.*
	
	metadata {
	definition (name: "NOAA Weather Alerts", namespace: "aaronward", author: "Aaron Ward") {
		capability "Refresh"
	}
	preferences {
		section {
			input (
				type: "bool",
				name: "enableDebugLogging",
				title: "Enable Debug Logging?",
				required: true,
				defaultValue: true
			)
		}
	}
}

def log(msg) {
	if (enableDebugLogging) {
		log.debug(msg)	
	}
}

def installed () {
	log.info "${device.displayName}.installed()"
    updated()
}

def updated () {
	log.info "${device.displayName}.updated()"
    runIn(5, refresh)				// But test it once, right after we install or update it too.
}

def refresh() {
		def wxURI = "https://api.weather.gov/alerts/active?status=actual&point=41.540583%2C-88.276465"

	def requestParams =
	[
		uri:  wxURI,
		requestContentType: "application/json",
		contentType: "application/json"
	]

	httpGet(requestParams)	{	  response ->
		if (response?.status == 200)
		{
			log.info response.data.features
			log.info response.data.features.id
		}
		else
		{
			log.warn "${response?.status}"
		}
	}

}

yielded this:

2019-02-19 04:22:59.975 pm [info](http://192.168.1.55/device/edit/194)[https://api.weather.gov/alerts/NWS-IDP-PROD-3381285-2960502]

1 Like

Looks like I left a comma out in my original code snippet post above... Sorry about that @aaron.

1 Like

Holy Json Batman. I've used json validators but nothing that formatted it so it was this easy to visually parse.
Bookmarking this one!!

1 Like

@ogiewon and @stephack

So I can get to response.data.features.id but you can't seem to parse anything further down. I need the following:

response.data.features.properties.sent
response.data.features.properties.description
response.data.features.properties.descArea

Thoughts?