How to handle "null" coming as string?
I do not want to update fields in my database when it is coming as null or as a "null" string. Bubble API connector is sending unset string fields as "null" string. I am using first_notempty as explained in the below video. But this doesn't seem to handle "null" strings. The only alternative way to handle this situation I could think of was to check those fields one by one for the "null" string and update it as actual null. Is there an easy way to handle "null" strings? There are a lot of fields and I think handling each one of them separately is not a good idea.
Best Answers
-
My solution should be pretty straightforward. Remove the enclosing parentheses in your API builder body. In your expression builder for the text string that is sometimes null, add the operator “:format as Json safe” as the last step in the expression. Be sure to set that input as “optional” and “can be empty” in the api builder.
now, bubble will automatically append parentheses to the expression where they are needed and it will use an actual null value instead of a string that says null
-
@Sourabh I suggest to avoid placing the quote marks in the hardcoded json body, instead pass the them as part of the input field, take a look at the image below and you will notice that I'm not placing them directly to the values.
Then, place the values and as @jared gibb mentioned format them as json safe (see image below)
Now if the value is empty it will pass the quotation marks alone ( "" ), if you place the quotation marks directly in the harcoded body it will send a parsing error if you use json safe (because it will pass a pair of quotation amrks between another pair of quotation marks) and if you don't use json safe will trhow an string with the value "null" when it is empty.
Answers
-
Also interested in that.
-
Hi @Sourabh unfortunately, this sounds like a potential bug on Bubble's platform. Since the text string "null" is a text string and not the actual value of null, it will not be recognized as empty, which is why first_notempty does not work in this scenario... To work around it, you are correct you will need to perform a check on each field if it is equal to the text string null then update it as null.
-
can you share a screenshot of your API setup in bubble? you should be able to leave empty and not send a string at all! :)
-
This is how API is set up in Bubble.
And this is how I am passing value. null comes fine in integer values like for "items_in_cart" but not for string values which are enclosed with double quotes
"
. Here for example I do not have the "last_name" of the user which becomes a "null" string.I have also started a thread in a bubble for this issue. Workaround in bubble also doesn't seem to be very straightforward.
Let me know if there is an easier/faster way to do this.
I am thinking of manually setting these "unset values" as actual null in bubble for now.
-
That's awesome @jared gibb! Thank you for dropping some Bubble knowledge!
-
-
Shout out to @Felipe Letelier and @jared gibb.
Huge thanks! This method has saved me after multiple other unsuccessful attempts trying to resolve the null text.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback