I apologize as I am new to JSON. Usually have been using XML for all these years. I'm trying to grab structs from a feed from the NWS.
So for example, here is the source: https://api.weather.gov/alerts/active?zone=OHC051
So I am setting using a cfset to grab a long feed. But here is an example of the beginning of it:
<cfset weather = '{
"@context": [
"https://geojson.org/geojson-ld/geojson-context.jsonld",
{
"version": "1.1",
"wx": "https://api.weather.gov/ontology",
"vocab": "https://api.weather.gov/ontology"
}
],
"type": "FeatureCollection",
"features": [
{
"id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.f70076597ffcf16333ee886fe424c7cc5e23cb1e.001.1",
"type": "Feature",
"geometry": null,
"properties": {
"@id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.f70076597ffcf16333ee886fe424c7cc5e23cb1e.001.1",
"@type": "wx:Alert",
"id": "urn:oid:2.49.0.1.840.0.f70076597ffcf16333ee886fe424c7cc5e23cb1e.001.1",
"areaDesc": "Lagrange; Steuben; Noble; De Kalb; Whitley; Allen; Huntington; Wells; Adams; St. Joseph; Branch; Hillsdale; Williams; Fulton; Defiance; Henry; Paulding; Putnam; Van Wert",
"geocode": {
"SAME": [
"018087",
"018151",
"018113",
"018033",
"018183",
"018003",
"018069",
"018179",
"018001",
"026149",
"026023",
"026059",
"039171",
"039051",
"039039",
"039069",
"039125",
"039137",
"039161"
],
"UGC": [
"INZ006",
"INZ007",
"INZ008",
"INZ009",
"INZ017",
"INZ018",
"INZ025",
"INZ026",
"INZ027",
"MIZ079",
"MIZ080",
"MIZ081",
"OHZ001",
"OHZ002",
"OHZ004",
"OHZ005",
"OHZ015",
"OHZ016",
"OHZ024"
]
},
"affectedZones": [
"https://api.weather.gov/zones/forecast/INZ006",
"https://api.weather.gov/zones/forecast/INZ007",
"https://api.weather.gov/zones/forecast/INZ008",
"https://api.weather.gov/zones/forecast/INZ009",
"https://api.weather.gov/zones/forecast/INZ017",
"https://api.weather.gov/zones/forecast/INZ018",
"https://api.weather.gov/zones/forecast/INZ025",
"https://api.weather.gov/zones/forecast/INZ026",
"https://api.weather.gov/zones/forecast/INZ027",
"https://api.weather.gov/zones/forecast/MIZ079",
"https://api.weather.gov/zones/forecast/MIZ080",
"https://api.weather.gov/zones/forecast/MIZ081",
"https://api.weather.gov/zones/forecast/OHZ001",
"https://api.weather.gov/zones/forecast/OHZ002",
"https://api.weather.gov/zones/forecast/OHZ004",
"https://api.weather.gov/zones/forecast/OHZ005",
"https://api.weather.gov/zones/forecast/OHZ015",
"https://api.weather.gov/zones/forecast/OHZ016",
"https://api.weather.gov/zones/forecast/OHZ024"
],
"references": [],
"sent": "2024-01-30T21:32:00-05:00",
"effective": "2024-01-30T21:32:00-05:00",
"onset": "2024-01-30T21:32:00-05:00",
"expires": "2024-01-31T05:45:00-05:00",
"ends": "2024-01-31T09:00:00-05:00",
"status": "Actual",
"messageType": "Alert",
"category": "Met",
"severity": "Moderate",
"certainty": "Likely",
"urgency": "Expected",
"event": "Dense Fog Advisory",
"sender": "[email protected]",
"senderName": "NWS Northern Indiana",
"headline": "Dense Fog Advisory issued January 30 at 9:32PM EST until January 31 at 9:00AM EST by NWS Northern Indiana",
"description": "* WHAT...Visibility one quarter to one half mile in dense fog.\n\n* WHERE...Portions of northern Indiana, southwest Michigan and\nnorthwest Ohio.\n\n* WHEN...Until 9 AM EST Wednesday.\n\n* IMPACTS...Hazardous driving conditions due to low visibility.",
"instruction": "If driving, slow down, use your headlights, and leave plenty of\ndistance ahead of you.",
"response": "Execute",
"parameters": {
"AWIPSidentifier": [
"NPWIWX"
],
"WMOidentifier": [
"WWUS73 KIWX 310232"
],
"NWSheadline": [
"DENSE FOG ADVISORY IN EFFECT UNTIL 9 AM EST WEDNESDAY"
],
"BLOCKCHANNEL": [
"EAS",
"NWEM",
"CMAS"
],
"VTEC": [
"/O.NEW.KIWX.FG.Y.0003.240131T0232Z-240131T1400Z/"
],
"eventEndingTime": [
"2024-01-31T14:00:00+00:00"
]
}
}
},
{
"id": "https://api.weather.gov/alerts/urn:oid:2.49.0.1.840.0.2b7ae562fae2efebc0268af8a1e8209d22031ef5.005.1",
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-84.439999999999998,
41.299999999999997
],
[
-84.4599999,
41.489999999999995
],
[
-84.390000000000001,
41.589999999999996
],
[
-84.290000000000006,
41.589999999999996
],
[
-84.38000000000001,
41.299999999999997
],
[
-84.439999999999998,
41.299999999999997
]
]
]
},
At the end I am trying to perform a writeout similar to the following:
<cfscript>
record=deserializeJSON(#weather#);
writeOutput(record.type.features.type & " ");
</cfscript>
One of the biggest problems I have is trying to identify the vars. So for example... I have been get vars like the following: areaDesc, effective, event and description.
But for the life of me I cannot get it to work. Wait I misspoke... I was able to get writeOutput(record.type & " "); to work and display "FeatureCollection" but that is it.
Not looking for someone to do my work.... but just have been at this for a long time and an hitting a wall. Any help would be greatly appreciated.
Thank you.