Trouble retrieving the recipe from spoonulacular API (using teachable machine)

can you paste here exactly what you are receiving in the responseContent (before any conversion)?

of course, buddy! here it is:

:blossom: :blossom: :blossom:

Not a screenshot of your responseContent, but the content of the responseContent. Check here how do it and then paste here the received response:
How to show raw responseContent from your app when debugging - Tutorials and Guides - MIT App Inventor Community

like this?
[{"id":654515,"image":"","imageType":"jpg","likes":1,"missedIngredientCount":2,"missedIngredients":[{"aisle":"Produce","amount":5,"id":2004,"image":"","meta":["(from my garden)"],"name":"pandan leaves click here cut to 2" length","original":"5 Pandan leaves click here (from my garden) cut to 2" length","originalName":"Pandan leaves click here (from my garden) cut to 2" length","unit":"","unitLong":"","unitShort":""},{"aisle":"Nut butters, Jams, and Honey","amount":6,"id":19296,"image":"","meta":["to taste"],"name":"honey or","original":"6 tablespoons Honey or to taste","originalName":"Honey or to taste","unit":"tablespoons","unitLong":"tablespoons","unitShort":"Tbsp"}],"title":"Pandan Smoothie","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":100,"id":11206,"image":"","meta":["cut into small cubes"],"name":"cucumber","original":"100 grams Cucumber, cut into small cubes","originalName":"Cucumber, cut into small cubes","unit":"grams","unitLong":"grams","unitShort":"g"},{"aisle":"Produce","amount":3,"id":9200,"image":"","meta":["peeled","quartered"],"name":"oranges","original":"3 Oranges, peeled and quartered","originalName":"Oranges, peeled and quartered","unit":"","unitLong":"","unitShort":""}]}, {"id":639512,"image":"","imageType":"png","likes":7,"missedIngredientCount":4,"missedIngredients":[{"aisle":"Produce","amount":2,"id":11959,"image":"","meta":,"name":"arugula","original":"2 cups arugula","originalName":"arugula","unit":"cups","unitLong":"cups","unitShort":"cup"},{"aisle":"Produce","amount":2,"id":11429,"image":"","meta":["thinly sliced"],"name":"radish","original":"2 radish, thinly sliced","originalName":"radish, thinly sliced","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":1,"id":11291,"image":"","meta":["chopped"],"name":"green onion","original":"1 green onion, chopped","originalName":"green onion, chopped","unit":"","unitLong":"","unitShort":""},{"aisle":"Seafood","amount":8,"id":10015172,"image":"","meta":,"name":"scallops","original":"8 scallops","originalName":"scallops","unit":"","unitLong":"","unitShort":""}],"title":"Citrus Arugula Salad with Seared Scallops","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":1,"id":9200,"image":"","meta":,"name":"cara cars orange","original":"1 cara cars orange","originalName":"cara cars orange","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":0.5,"extendedName":"english persian cucumber","id":10111205,"image":"","meta":["english","thinly sliced","(or cucumber)"],"name":"persian cucumber","original":"1/2 persian cucumber (or english cucumber), thinly sliced","originalName":"persian cucumber (or english cucumber), thinly sliced","unit":"","unitLong":"","unitShort":""}]}]

1 Like

It seems it is not a well formed JSON...

also fields with no values:


1 Like

I don't know what to do with it, this is exactly how i received it from the spoonacular API . is the issue with the Api itself or my app :frowning:

You can try to manipulate the response received to delete all those malformed parts:

the question is if for other request you will have responses with other weird fields....
For example, with the above example of @ABG this example will not work...

(EDIT: I have changed the example by other more generic)

Other option could be extract the info directly from the response string but this can be quite cumbersome depending on the information you want to extract.

I'm so sorry, I made a mistake. These fields without values ​​are due to the fact that when you copied the JSON that you have left, the empty fields [ ] have been pasted as and then they have not been pasted correctly in my example. Apologies. By removing that part of "length" you should be able to decode it correctly:

1 Like

Thank you for your reply buddy. :blossom: :dizzy: Will this work though for different recipes? since my app will take different variables based on the users preferences and have the API retrieve recipes for them. I will continue working on my app and i will see if your code fixes the problem.<333

Looking to the @ABG examples:

name": "pandan leaves click here cut to 2\" length",

you can se the double quotes after the 2 are escaped (2 \ ") what you have pasted that double quotes are not escaped (2").

This difference is why you have to put that first additional block removing "length "".

But if your response have that double quoted escaped like in the other examples (maybe other error copy-pasting) then you don't need that additional block.

It is important to find out that because what works for one scenario will not work for the other so, try without the additional block:

1 Like

I will try both and tomorrow I will show you the results. thanks! <33 :herb:

Sorry for the mistakes... :pensive:

1 Like

I found the recipe JSON unparseable using the DecodeJSONAsDictionaries block, but the older DecodeJSON block was able to parse it without errors, albeit into lists of pairs.

So here is some rudimentary browsing and display code:

spoonacular.aia (7.5 KB)

I leave it up to you to prettify the output.

1 Like

I forgot I had this in stock for displaying structures by indentation:
tidy_JSON.aia (4.4 KB)


another way to pretty jsonString:



One last note about spoonacular recipes.

I didn't see anything about preparation instructions.

Maybe they just do salads?


don't say that friend! you've done more than enough to help me thank you! <33

1 Like

I think its because the ingredients that i use for this app are mostly fruits and veggies. :grapes: :watermelon: :strawberry: :blueberries:

I really want to thank you guys @ABG @NishyanthKumar @Kevinkun @Ramon for helping me so much with this and being so kind too! :blossom: i want to show you were i got, and i think you'll be very proud! :dizzy: i managed to translate the Json text after organizing it like you showed me and now i can receive the titles and the steps of the recipies like i wanted :partying_face: :partying_face: i will show you the code and the screen (in the companion app):

up until here it all works like a charm! and i think i am finally understand the basic of dealing with dictionaries :partying_face: the only problem i may be facing is splitting the recipes apart (their titles and steps("original") i am currently working on fixing that wish me luck!

this is the screen :

Once i am done with this app i will put the entire app (.aia) here so everyone can use it and i will add your names for your help! :slight_smile: :smile: :blossom:


(added to FAQ)