get an object property only when it's present in the object

Options
Hi there,
I'm having several troubles manipulating data with Xano 😅
Here is the (first?) trouble of the day.

I get some data from an external API, wich may or may not contains a "styles" and/or "genres" property.
Then, I try to create a new object with a "class" property which value should be the styles value (wich is an array of texts) of the original object or the genres value (same type) if the styles property doesn't exist.

How could I do that?
I tried many combinations but got an error each time the "styles" property doesn't exist in the original object.

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     - you can define the path using the GET filter which will allow you to define a default value such as null in the event that the property doesn't exist. This way you can add in logic like a conditional to do something if the property is/is not equal to null
  • Brandon Hassler
    Options
    So glad I found this post! This simple filter has allowed me to delete a ton of unnecessary IF/THEN statements I've built out :)