Looking for help parsing [[ and ]] out of a HTTP "Get" response


#1

I’m testing a simple use of Bing’s Geolocation API to assign a physical address to the latitude and longitude reported by the webCoRE presence sensor. It’s working great, but the $response is coming with [[ ]] surrounding the values. I’m feeling dumb that I can’t figure out how to remove those square brackets before I set my variable!

Piston is here:

EDIT:
I found another service (called Nominatim, uses OpenStreetMap.org info) that doesn’t require a private Key and still gives me what I want, without any formatting problems. Solved!

Updated piston below:


#2

For future reference, If you treat it like a string, you can use the replace function:
unbracketed=replace(replace($response, “[”, “”), “]”, “”)


#3

Hey folks, I am having a similar issue and I think that I know the problem… Looking for verification.
I have a GET Request sending out that returns JSON (this is verified through the browser.) However, when I put the GET request in my Piston, I get an error message trying to Parse the JSON. I believe that this is because the return that WebCoRE is seeing isn’t formatted properly for JSON…

Anyone offer any thoughts on how to resolve this? I want the reponse to be able to be loaded into a dynamic variable where I can call the various attributes $response:attribute.value as my JSON return can be quite complicated.

Message in the log:

Error parsing JSON data currently:[apparentTemperature:77.05, cloudCover:0.6, dewPoint:61.17, humidity:0.58, icon:partly-cloudy-day, nearestStormBearing:334, nearestStormDistance:65, ozone:347.14, precipIntensity:0, precipProbability:0, pressure:1011.99, summary:Mostly Cloudy, temperature:76.92, time:1560449476, uvIndex:6, visibility:10, windBearing:203, windGust:8.96, windSpeed:7.81], daily:data:apparentTemperatureHigh:79.66, apparentTemperatureHighTime:1560459600, apparentTemperatureLow:54.51, apparentTemperatureLowTime:1560502800, apparentTemperatureMax:79.66, apparentTemperatureMaxTime:1560459600, apparentTemperatureMin:60.4, apparentTemperatureMinTime:1560405600, cloudCover:0.63, dewPoint:57.91, humidity:0.72, icon:partly-cloudy-day, moonPhase:0.38, ozone:333.64, precipIntensity:0.0005, precipIntensityMax:0.0038, precipIntensityMaxTime:1560456000, precipProbability:0.21, precipType:rain, pressure:1012.81, summary:Mostly cloudy until afternoon., sunriseTime:1560420660, sunsetTime:1560472890, temperatu…[TRUNCATED]

Screenshot of what the variable value gets set to:

Thanks in advance
-CT


#4

Also, I have seen older posts that seem to imply that I can specify my Get request as “with JSON” to treat the response as a JSON value… But this option currently (v0.3.10c) only seems to be available for POST requests.


#5

You can try $response.currently.apparentTemperature to pull 77.05 from that json response. Do the same for all the data you need.


#6

Thanks this worked as expected…

So in what scenario would I use the Parse JSON activity?


#7

I’ve not used parse json task before but here’s a old post from @ady624