How do i handle object with no keys or empty value OR missing object in a API request?

Options

Hi there! I'm pulling data from the tasty API and is facing a challenge. I've build a function stack to pull nutrition values from the get recipes/get-more-info endpoint. But it seems that the function stack will stop running when it runs into a recipe that has either the 'nutrition' object with no keys or is missing totally.

This is how the results from the endpoint looks like

this is how i set up the function stack.

i tried using get filter in 2.3 but it doesn't seem to work. i think i might have implement it wrongly. would love to get an idea on how typically this is being handled. i've limited technical knowledge and i'm mainly a self-learner on this. any advice would be appreciated!

thanks!

Answers

  • Lefteris - blupry.com
    Options

    Hey @ounced,

    Have you tried using the Object manipulation tools Xano offers you?

    If you go into Data Manipulation → Objects, you will see two interesting functions "Get Keys" and "Get Values".

    You could use "Get Keys" in order to see if the field "nutrition" exists. To do so, you just throw your object as input on the function, and then use the "Has Any Element" function on the table output of the "Get keys". If $this=nutrition is true, then the result of "Has Any Element" is true!

    Now in order to check if the value is empty, you can use either "Get Values" or directly use "If recipeDetails.nutrition = null, then you can proceed into removing they property name "nutrition" completely and creating a new object where you append the rest of the values.

    I am pretty sure that I did not explain that in the best way, so don't hesitate asking for any further clarification!