jsonDecode parsing not working in 7.8.3 but is in 7.8.1

I have two separate Ignition instances running identical code. 7.8.1 can parse a json stream from a http site and my 7.8.3 instance can not. In looking at the change log I could not find any system.util.jsonDecode improvements.

On the 7.8.1 instance json_string is a json string and parsed_jason is a dictionary (works as expected)
On the 7.8.3 instance both are json strings and I do not receive any parsing errors. The last print statement does error because parsed_jason is not a dictionary.
Does anyone know why the two would run differently?

[code]

Query Weather Underground for weather alerts

def getAlerts():
import urllib2
f = urllib2.urlopen(‘http://api.wunderground.com/api/MyKeyCode/geolookup/alerts/q/IA/Orange_City.json’)
json_string = f.read()
f.close()
parsed_json = system.util.jsonDecode(json_string)
print json_string
print parsed_json
print "location: ", parsed_json[‘location’][‘city’][/code]

There were some (ostensibly) corrections made to the jsonDecode function at some point. I can’t say for sure if it’s now acting correctly or not without seeing the JSON you’re getting back and maybe what the object it’s being parsed into looks like.

Looks like we did make some changes to jsonDecoding in 7.7.7, and those changes got pulled into 7.8.2. The change log entry from 7.7.7 says “Fixes bug in jsonDecode() that caused strings containing numbers to be decoded as numbers.” Not sure if that’s causing the difference you see, but it sure seems suspicious…

Here is the output from the URL. I’m trying to put it into a dictionary where I can grab storm warnings

{ "response": { "version":"0.1", "termsofService":"http://www.wunderground.com/weather/api/d/terms.html", "features": { "geolookup": 1 , "alerts": 1 } } , "location": { "type":"CITY", "country":"US", "country_iso3166":"US", "country_name":"USA", "state":"CA", "city":"Poway", "tz_short":"PDT", "tz_long":"America/Los_Angeles", "lat":"32.97999954", "lon":"-117.04000092", "zip":"92064", "magic":"1", "wmo":"99999", "l":"/q/zmw:92064.1.99999", "requesturl":"US/CA/Poway.html", "wuiurl":"https://www.wunderground.com/US/CA/Poway.html", "nearby_weather_stations": { "airport": { "station": [ { "city":"Ramona", "state":"CA", "country":"US", "icao":"KRNM", "lat":"33.03749847", "lon":"-116.91583252" } ,{ "city":"Miramar MCAS", "state":"CA", "country":"US", "icao":"KNKX", "lat":"32.86454010", "lon":"-117.13661194" } ,{ "city":"Santee", "state":"CA", "country":"US", "icao":"KSEE", "lat":"32.82622147", "lon":"-116.97244263" } ,{ "city":"San Diego Montgomery", "state":"CA", "country":"US", "icao":"KMYF", "lat":"32.81572342", "lon":"-117.13957977" } ] } , "pws": { "station": [ { "neighborhood":"Midland Road Extension", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY67", "lat":32.982857, "lon":-117.040390, "distance_km":0, "distance_mi":0 }, { "neighborhood":"Midland Gardens", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY37", "lat":32.984116, "lon":-117.039978, "distance_km":0, "distance_mi":0 }, { "neighborhood":"Twin Circle Court", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY54", "lat":32.975670, "lon":-117.043198, "distance_km":0, "distance_mi":0 }, { "neighborhood":"Arbolitos", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY58", "lat":32.981564, "lon":-117.052002, "distance_km":1, "distance_mi":0 }, { "neighborhood":"Paseo De La Huerta", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY40", "lat":32.993382, "lon":-117.039864, "distance_km":1, "distance_mi":0 }, { "neighborhood":"Paseo De La Huerta", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY45", "lat":32.993511, "lon":-117.040161, "distance_km":1, "distance_mi":0 }, { "neighborhood":"Twin Peaks and Espola", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY30", "lat":32.978634, "lon":-117.020638, "distance_km":1, "distance_mi":1 }, { "neighborhood":"Beechwood Street", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY75", "lat":32.967670, "lon":-117.053741, "distance_km":1, "distance_mi":1 }, { "neighborhood":"Arbolitos", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY72", "lat":32.967579, "lon":-117.053673, "distance_km":1, "distance_mi":1 }, { "neighborhood":"Country Hill Road", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY83", "lat":32.988464, "lon":-117.017365, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Adobe Hills", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY2", "lat":32.983601, "lon":-117.064819, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Green Valley Highlands", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY16", "lat":33.001198, "lon":-117.037811, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Green Valley Highlands DP2", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY32", "lat":33.001263, "lon":-117.037796, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Eastern Poway", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY10", "lat":32.960861, "lon":-117.019798, "distance_km":2, "distance_mi":1 }, { "neighborhood":"Poway Rd/Midland", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY21", "lat":32.954250, "lon":-117.035683, "distance_km":2, "distance_mi":1 }, { "neighborhood":"APRSWXNET", "city":"Poway", "state":"CA", "country":"US", "id":"ME3241", "lat":32.960468, "lon":-117.019249, "distance_km":2, "distance_mi":1 }, { "neighborhood":"High Valley", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY88", "lat":32.992653, "lon":-117.010750, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Parview Estates", "city":"San Diego", "state":"CA", "country":"US", "id":"KCASANDI589", "lat":32.995453, "lon":-117.068344, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Green Valley Highlands North", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY42", "lat":33.008369, "lon":-117.036201, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Bridlewood - Lake Poway", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY82", "lat":33.000904, "lon":-117.014694, "distance_km":3, "distance_mi":1 }, { "neighborhood":"Espola and Lake Poway Road", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY47", "lat":33.006817, "lon":-117.022911, "distance_km":3, "distance_mi":2 }, { "neighborhood":"MesoWest", "city":"Poway", "state":"CA", "country":"US", "id":"MSDPWE", "lat":32.994999, "lon":-117.008003, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Lake Poway/Bridlewood", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY68", "lat":33.004658, "lon":-117.017868, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Bridlewood", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY62", "lat":33.004608, "lon":-117.015739, "distance_km":3, "distance_mi":2 }, { "neighborhood":"8 Palms Ranchero Poway, CA", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY33", "lat":32.950218, "lon":-117.025726, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Bridlewood American", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY85", "lat":33.009918, "lon":-117.025475, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Bernardo Heights", "city":"San Diego", "state":"CA", "country":"US", "id":"KCASANDI160", "lat":32.994450, "lon":-117.075256, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Poway Estates", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY9", "lat":32.954151, "lon":-117.064392, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Bridlewood", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY89", "lat":33.012383, "lon":-117.027855, "distance_km":3, "distance_mi":2 }, { "neighborhood":"Carmel Mountain Ranch", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY86", "lat":32.969673, "lon":-117.078857, "distance_km":3, "distance_mi":2 }, { "neighborhood":"North Poway", "city":"Poway", "state":"CA", "country":"US", "id":"KCAPOWAY53", "lat":33.014328, "lon":-117.026520, "distance_km":4, "distance_mi":2 }, { "neighborhood":"APRSWXNET", "city":"Poway", "state":"CA", "country":"US", "id":"ME9437", "lat":33.000000, "lon":-117.000000, "distance_km":4, "distance_mi":2 } ] } } } ,"query_zone": "050", "alerts": [ ] }

Call .strip() on your response JSON string before you decode it… it appears to be very sensitive when it comes to the first character and if it starts with a newline it doesn’t decode properly.

Works great! Here is my new code. Thanks for the help

[code]

Query Weather Underground for weather alerts

def getAlerts():
import urllib2
f = urllib2.urlopen(‘http://api.wunderground.com/api/MyKeyCode/geolookup/alerts/q/IA/Orange_City.json’)
json_string = f.read()
f.close()
parsed_json = system.util.jsonDecode(json_string.strip())
print json_string
print parsed_json
print "location: ", parsed_json[‘location’][‘city’][/code]