API - JSON Output

Hello,

I am building an app with should display the cheapest gas station to your current location (+/- 5 KM)
I only want to display the "name" , "price" and "street" of the following output after clicking the button "Search". (Only the first gas station of the output ). (from API "Tankerkönig"). I tried it with json text decode, but unfortunately it doesn't work.
{
"ok": true,
"license": "CC BY 4.0 - https://creativecommons.tankerkoenig.de",
"data": "MTS-K",
"status": "ok",
"stations": [
{ Datentyp, Bedeutung
"id": "474e5046-deaf-4f9b-9a32-9797b778f047", - UUID, eindeutige Tankstellen-ID
"name": "TOTAL BERLIN", - String, Name
"brand": "TOTAL", - String, Marke
"street": "MARGARETE-SOMMER-STR.", - String, Straße
"place": "BERLIN", - String, Ort
"lat": 52.53083, - float, geographische Breite
"lng": 13.440946, - float, geographische Länge
"dist": 1.1, - float, Entfernung zum Suchstandort in km
"diesel": 1.109,
"e5": 1.339, - float, Spritpreise in Euro
"e10": 1.319, /
"isOpen": true, - boolean, true, wenn die Tanke zum Zeitpunkt der
Abfrage offen hat, sonst false
"houseNumber": "2", - String, Hausnummer
"postCode": 10407 - integer, PLZ
},
Thanks in advance for your help.....

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

To get an image of your blocks, right click in the Blocks Editor and select "Download Blocks as Image". You might want to use an image editor to crop etc. if required. Then post it here in the community.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

IMG_1189

Now right click on some white space in your blocks editor and download an image of your blocks. Post that here so we can actually read it

1 Like

OK, you are close.

Can you provide the raw output of the responseContent then someone can suggest the correct dictionary/list blocks that you need.

  1. Is this real output of the json?
  2. There is no price key in the above code.
  3. If you show us the correct value it will be easy to suggest you

If json structure correct mean, you will need to use list by walking path {make a list, stations, price} dictionary call web1 to decode the json text get response content

The above code will give price list if exist, instead of price if you use name it will give you name list ..

One more suggestion, instead of jsontextDecodeDictionaries try with json decode text block and try

{"ok":true,"license":"CC BY 4.0 - https://creativecommons.tankerkoenig.de","data":"MTS-K","status":"ok","stations":[{"id":"b22c0e24-9ac1-4acc-9b48-fe2b4b1e86b6","name":"SB-Markttankstelle Wei\u00dfenburg Eichst\u00e4tter Str.","brand":"SB-Markttankstelle","street":"Eichst\u00e4tter Str.","place":"Wei\u00dfenburg","lat":49.02656,"lng":10.984426,"dist":3.2,"price":1.729,"isOpen":true,"houseNumber":"29","postCode":91781},{"id":"9947a79d-1e6e-4413-83b7-3671cd765355","name":"Steil Energie","brand":"AVIA XPress","street":"Am Sand","place":"Wei\u00dfenburg","lat":49.0205692,"lng":10.9444183,"dist":4.7,"price":1.729,"isOpen":true,"houseNumber":"13","postCode":91781},{"id":"d1cf1eb4-799f-4b82-95c6-e4f231019f93","name":"T Weissenburg","brand":"T","street":"Augsburger Str.","place":"Weissenburg","lat":49.021417,"lng":10.965927,"dist":3.4,"price":1.739,"isOpen":true,"houseNumber":"61","postCode":91781},{"id":"cbafd3c0-a150-4508-9d39-2ee079a68ada","name":"Wei\u00dfenburg","brand":"tankpool24","street":"Dettenheimer Stra\u00dfe 70","place":"Wei\u00dfenburg","lat":49.00177,"lng":10.95062,"dist":3.6,"price":1.739,"isOpen":true,"houseNumber":"","postCode":91781},{"id":"51d4b681-a095-1aa0-e100-80009459e03a","name":"JET WEISSENBURG NUERNBERGER STR. 53","brand":"JET","street":"NUERNBERGER STR.","place":"WEISSENBURG","lat":49.0396,"lng":10.9704,"dist":4.9,"price":1.739,"isOpen":true,"houseNumber":"53","postCode":91781},{"id":"acf0c07f-1c5b-4c1f-99e3-57d502dda01f","name":"Bft Weissenburg Augsburger Stra\u00dfe 18","brand":"bft","street":"Augsburger Stra\u00dfe","place":"Weissenburg","lat":49.02491,"lng":10.966925,"dist":3.7,"price":1.749,"isOpen":true,"houseNumber":"18","postCode":91781},{"id":"754ea764-cd61-4528-a200-28b432087b2e","name":"Aral Tankstelle","brand":"ARAL","street":"N\u00fcrnberger Stra\u00dfe","place":"Wei\u00dfenburg","lat":49.038826,"lng":10.9709082,"dist":4.8,"price":1.749,"isOpen":true,"houseNumber":"44","postCode":91781},{"id":"97305a76-6175-4824-a55e-97da5d886ca8","name":"WEISSENBURG - N\u00dcRNBERGER STRASSE 5","brand":"AGIP ENI","street":"N\u00fcrnberger Strasse","place":"Weissenburg","lat":49.039097,"lng":10.970397,"dist":4.9,"price":1.749,"isOpen":true,"houseNumber":"51","postCode":91781}]}

Only the first gas station in the output is needed. (name, street, price)

hope anyone can help :slight_smile:

I attached the screenshot

Did you try the block that i suggest above?

Hello,

I am building an app with should display the cheapest gas station to your current location (+/- 5 KM)
I only want to display the "name" , "price" and "street" of the following output after clicking the button "Search". (Only the first gas station of the output ). (from API "Tankerkönig"). I tried it with json text decode, but unfortunately it doesn't work. I got the Error Message: "not found" for all three items... Thanks for your help in advance

Here the Json Output & Code:

{"ok":true,"license":"CC BY 4.0 - https://creativecommons.tankerkoenig.de","data":"MTS-K","status":"ok","stations":[{"id":"b22c0e24-9ac1-4acc-9b48-fe2b4b1e86b6","name":"SB-Markttankstelle Wei\u00dfenburg Eichst\u00e4tter Str.","brand":"SB-Markttankstelle","street":"Eichst\u00e4tter Str.","place":"Wei\u00dfenburg","lat":49.02656,"lng":10.984426,"dist":3.2,"price":1.729,"isOpen":true,"houseNumber":"29","postCode":91781},{"id":"9947a79d-1e6e-4413-83b7-3671cd765355","name":"Steil Energie","brand":"AVIA XPress","street":"Am Sand","place":"Wei\u00dfenburg","lat":49.0205692,"lng":10.9444183,"dist":4.7,"price":1.729,"isOpen":true,"houseNumber":"13","postCode":91781},{"id":"d1cf1eb4-799f-4b82-95c6-e4f231019f93","name":"T Weissenburg","brand":"T","street":"Augsburger Str.","place":"Weissenburg","lat":49.021417,"lng":10.965927,"dist":3.4,"price":1.739,"isOpen":true,"houseNumber":"61","postCode":91781},{"id":"cbafd3c0-a150-4508-9d39-2ee079a68ada","name":"Wei\u00dfenburg","brand":"tankpool24","street":"Dettenheimer Stra\u00dfe 70","place":"Wei\u00dfenburg","lat":49.00177,"lng":10.95062,"dist":3.6,"price":1.739,"isOpen":true,"houseNumber":"","postCode":91781},{"id":"51d4b681-a095-1aa0-e100-80009459e03a","name":"JET WEISSENBURG NUERNBERGER STR. 53","brand":"JET","street":"NUERNBERGER STR.","place":"WEISSENBURG","lat":49.0396,"lng":10.9704,"dist":4.9,"price":1.739,"isOpen":true,"houseNumber":"53","postCode":91781},{"id":"acf0c07f-1c5b-4c1f-99e3-57d502dda01f","name":"Bft Weissenburg Augsburger Stra\u00dfe 18","brand":"bft","street":"Augsburger Stra\u00dfe","place":"Weissenburg","lat":49.02491,"lng":10.966925,"dist":3.7,"price":1.749,"isOpen":true,"houseNumber":"18","postCode":91781},{"id":"754ea764-cd61-4528-a200-28b432087b2e","name":"Aral Tankstelle","brand":"ARAL","street":"N\u00fcrnberger Stra\u00dfe","place":"Wei\u00dfenburg","lat":49.038826,"lng":10.9709082,"dist":4.8,"price":1.749,"isOpen":true,"houseNumber":"44","postCode":91781},{"id":"97305a76-6175-4824-a55e-97da5d886ca8","name":"WEISSENBURG - N\u00dcRNBERGER STRASSE 5","brand":"AGIP ENI","street":"N\u00fcrnberger Strasse","place":"Weissenburg","lat":49.039097,"lng":10.970397,"dist":4.9,"price":1.749,"isOpen":true,"houseNumber":"51","postCode":91781}]}


tankerkoenig.aia (4.6 KB)





I wasn't sure your JSON was correct, so here is a shredder approach (give or take an umlaut.)

Screenshot_2022-12-22-00-20-16-00

1 Like

With Lists...

image

(assumes the json always comes back in the same order.......you could iterate over each level of the list to find the correct indexes....)

here's my output:

using these blocks

and aia
petrol.aia (3.5 KB)

Now it works, thank you very much :slight_smile:

It seems you don't wanna the whole list.. you want only one item and that too first item only .. if so already @TIMAI2 provided earlier and as well as @ABG too with full list ..

Next time if possible please be more specific.

He was....

1 Like