how to use new json parser to create an array?

246 views
Skip to first unread message

Mike T

unread,
Sep 22, 2022, 10:03:43 PM9/22/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 AM9/26/22
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!

Martin Schlender

unread,
May 11, 2023, 2:47:01 PMMay 11
to Tasker
Hey thanks for the answer. It helped a lot. Could you give me an idea on how to read several values from JSON into one array?
For example:
[
{
"station": "Supermarkt-Tankstelle Dettingen",
"status": "open",
"e5": 1.729,
"differenceE5": -0.03,
"e10": 1.669,
"differenceE10": -0.03,
"diesel": 1.509,
"differenceDiesel": -0.03,
"discount": "0"
},
{
"station": "Shell Neuhausen",
"status": "open",
"e5": 1.789,
"differenceE5": -0.03,
"e10": 1.739,
"differenceE10": -0.03,
"diesel": 1.559,
"differenceDiesel": 0.04,
"discount": "0"
},
{
"station": "OMV Metzingen",
"status": "open",
"e5": 1.779,
"differenceE5": 0.04,
"e10": 1.719,
"differenceE10": 0.04,
"diesel": 1.569,
"differenceDiesel": 0.04,
"discount": "0"
},
{
"station": "Shell Metzingen",
"status": "open",
"e5": 1.789,
"differenceE5": -0.04,
"e10": 1.739,
"differenceE10": -0.04,
"diesel": 1.559,
"differenceDiesel": 0.04,
"discount": "0"
},
{
"station": "Miller Metzingen",
"status": "open",
"e5": 1.719,
"differenceE5": -0.04,
"e10": 1.659,
"differenceE10": -0.04,
"diesel": 1.499,
"differenceDiesel": -0.01,
"discount": "0"
},
{
"station": "Total Metzingen",
"status": "open",
"e5": 1.709,
"differenceE5": -0.05,
"e10": 1.669,
"differenceE10": -0.05,
"diesel": 1.519,
"differenceDiesel": -0.05,
"discount": "0"
},
{
"station": "avanti Metzingen",
"status": "open",
"e5": 1.699,
"differenceE5": -0.01,
"e10": 1.639,
"differenceE10": -0.01,
"diesel": 1.499,
"differenceDiesel": -0.03,
"discount": "0"
}
]

And I would like to have an array with the station + e10 concatenated like:
Supermarkt-Tankstelle Dettingen 1.669, Shell Neuhausen 1.739
Is this possible with one array set command or do I need two array, fill them independently like:
Array Set [ Variable Array: %tabelle Values: %arcomm.station() Splitter: , ]
thanks
Martin

Martin Schlender

unread,
May 11, 2023, 2:59:40 PMMay 11
to Tasker
Ah - found it myself:

Arrays Merge does the trick
Task: List Test
A1: Arrays Merge [
Names: %arcomm.e10
%arcomm.station
Merge Type: Simple
Joiner:
Output: %tabelle ]
A2: List Dialog [
Mode: Select Single Item
Title: Test
Items: %tabelle
Button 1: ok
Button 2: cancel
Close After (Seconds): 30
First Visible Index: 0 ]

João Dias

unread,
May 12, 2023, 3:40:38 AMMay 12
to tas...@googlegroups.com
Nice! :) Glad you got it!

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias


Reply all
Reply to author
Forward
0 new messages