r/tasker • • May 14 '22

Help JSON help required

Hello friends, I'm trying to get Points of interest data from TomTom API. I get the following json dats

https://drive.google.com/file/d/1DlJ3YaAlms2rZ4vPkgZ3KYHyIWYw1Su0/view?usp=drivesdk

I want to make this into readable data. Eg. I get a list of Restaurants with their distance away from my location. If distance is not possible then the address would do.

I'm hoping some of you experts help me with this. I have been struggling with this for a long time. :)

2 Upvotes

8 comments sorted by

1

u/azekt May 14 '22 edited May 14 '22

Here it is:

Task: Tomtom

A1: Read File [
     File: Download/TomTomPOIraw.txt
     To Var: %tab
     Structure Output (JSON, etc): On ]

A2: Variable Set [
     Name: %results
     To: %tab.results
     Max Rounding Digits: 3
     Structure Output (JSON, etc): On ]

A3: For [
     Variable: %counter
     Items: 1:%results.poi(#)
     Structure Output (JSON, etc): On ]

    A4: Variable Set [
         Name: %str
         To: %counter: %results.poi.name(%counter) - %results.dist(%counter)
         
         Append: On
         Max Rounding Digits: 3
         Structure Output (JSON, etc): On ]

A5: End For

A6: Write File [
     File: tomtom_results.txt
     Text: %str ]

You can get whatever you want by adjusting A4 action.

0

u/SoliEngineer May 14 '22

Thank you fur you help. However only the 1$t row name repeats in all the rows. Also dist is not getting populated. Maybe I'm not able to understand the A4 action.. Would be grateful if you could drums an xml

1

u/azekt May 14 '22

0

u/SoliEngineer May 14 '22 edited May 14 '22

Wow, superb, thank you very much. Very kind of you. Just 1 more help... Suppose i want a search on only Restaurant and bars or Hospital instead of showing all the POIs mixed up, what/how should i get that?

PS: Also how can i round off the dist to 1 decimal?

1

u/azekt May 14 '22

Then you have to add if action and do some math. See upgraded task . In A5 use regex to find all categories you wish.

1

u/SoliEngineer May 14 '22

Ok i could get that But I'm not able to find a way to round off %results.dist(%counter) to 1 decimal.

1

u/azekt May 14 '22

As I did:

...

        A6: Variable Set [
             Name: %dist
             To: round(%results.dist(%counter)*10)/10
             Do Maths: On
             Max Rounding Digits: 3
             Structure Output (JSON, etc): On ]
   ...

1

u/SoliEngineer May 15 '22

Thank you for all your help.