how to use new json parser to create an array?

15 views
Skip to first unread message

Mike T

unread,
Sep 22, 2022, 10:03:43 PM (9 days ago) Sep 22
to Tasker
I am trying to parse json with weather data and I would like to copy a json array into a tasker array because the path to the variables I want is long and I'd rather use a shortened name for readability


    "time":{ "layoutKey":"k-p12h-n14-1", "startPeriodName":[ "Tonight", "Friday", "Friday Night", "Saturday", "Saturday Night", "Sunday", "Sunday Night", "Monday", "Monday Night", "Tuesday", "Tuesday Night", "Wednesday", "Wednesday Night", "Thursday"

I would like to store this into an array but I don't know how to do so.  I tried to use 

Array Set %array_days, http_data.time.startPeriodName(1) http_data.time.startPeriodName(2) 

but %array_days just gets the words as if they were text instead of recognizing them as json data that should be automatically parsed

Variable Set appears to perform the parsing since if I use

Variable Set %some_day,  http_data.time.startPeriodName(1)

then %some_day is  "Tonight"

  • why doesn't  Array Set parse the json?
  • is there a way to copy the  startPeriodName json array into a tasker array?

joaomgcd

unread,
Sep 26, 2022, 5:47:52 AM (6 days ago) Sep 26
to Tasker
Hi! :)

You can do it like this for example:

    Task: Test
   
    Variables: [ %test:has value ]
   
    A1: HTTP Request [
         Method: GET
         URL: https://forecast.weather.gov/MapClick.php?lat=37.498&lon=-122.267&FcstType=json
         Timeout (Seconds): 30
         Structure Output (JSON, etc): On ]
   
    A2: Array Set [
         Variable Array: %array_days
         Values: %http_data.time.startPeriodName()
         Splitter: , ]
   
    A3: List Dialog [
         Mode: Select Single Item
         Title: Days
         Items: %array_days
         Close After (Seconds): 30
         First Visible Index: 0 ]
   
    

Hope this helps!

Reply all
Reply to author
Forward
0 new messages