^jsonpath is fixed now in release 5.72
I created the following sample code to test a weather api:
$$answer = ^compute(^value - 273.15)
$$answer = ^compute($$answer * 1.80)
$$answer = ^compute($$answer + 32.00)
# $$answer = ^compute($$answer mod 100)
# $$answer = ^compute($$answer * 100)
$$answer = ^join($$answer f)
outputmacro: ^GetLocalWeather (^Town)
$$url = ^join(api.openweathermap.org/data/2.5/weather?q= ^Town) #limit 1000 requests/day
$$url_apikey = ^join($$url &appid;= $$APIKey)
$$jsonid = ^jsonopen(GET $$url_apikey “” “”)
# Uncomment to troubleshoot and see json response
$$Weather = ^jsonpath( .main jo-2)
$$WeatherDesc = ^jsonpath( .description jo-2)
$$Temp = ^jsonpath( .temp jo-3)
$$TempMin = ^jsonpath( .temp_min jo-3)
$$TempMax = ^jsonpath( .temp_max jo-3)
$$TempF = ^KelvinToFahrenheit($$Temp)
$$TempMinF = ^KelvinToFahrenheit($$TempMin)
$$TempMaxF = ^KelvinToFahrenheit($$TempMax)
You can expect $$WeatherDesc. It is $$TempF and will range from $$TempMinF to $$TempMaxF today.
topic: ~MyWeather ( weather )
u: ( what is the weather today ) ^keep() ^repeat()
$$MyTown = Los_Angelos
Welcome to ChatScript.
>what is the weather today?
You can expect sky is clear. It is 91.06f and will range from 84.20f to 99f today.
The weather descriptions returned from the api are not consistently structured so making one generic sentence to return the weather description results does not work. Another sample description is “scattered clouds” instead of “sky is cloudy”. Different custom responses to the user would need to be created for each weather description returned to sound more natural.
TIP: ^jsonpath can take a first argument with spaces if you use an underscore. In the sample above “temp min” was an object attribute name in the returned json but ^jsonpath( .temp_min jo-3) worked in referencing it and retrieving the value.
(Anyone know how to round to the nearest whole number in Chatscript? Also, basic math was not working so had to use a series of ^compute functions for converting Kelvin to Fahrenheit.)