Hi, I’m (still) a Thunkable n00b and haven’t been able to find a solution to this problem. I’m sure it’s simple, but I’m learning and could use some more help.
So, I’m building a lake data and local weather app for a friend with a lake house. The APIs I’m calling are returning “null” when there isn’t any info surfaced (i.e. for cloud cover and precipitation).
Instead of “null”, I’d like to display custom text like “Clear” or “None,” but I haven’t been able to find a solution in the docs or here.
Your if block is checking to see if null is true. I’m not even sure what that means. Computers are very literal so even though you’re thinking “I want to check if this cloud coverage value is null,” the actual blocks you used are just checking to see if the value null equals true or false. It has no idea that you want to refer to the API/JSON response at that point. There’s no context for that if condition.
What you want to check is if a specific (named) JSON property is null. So you’ll need to use the equals block from the Logic drawer.
What is the name of the JSON property you want to check and what is the value you want to check for? Is it null, is it zero, is it a blank string (“”)? If the name is data.cloud, then you would add that to the if condition. Also, double-check the spelling because when I looked at the Weatherbit documentation, it seems like that property might be called data.clouds.
Ahhh, ok. I appreciate you clarifying the process. Now it makes sense as to why it was failing – it didn’t understand, even though it was perfectly clear in my brain.
The 1st JSON property I want to check is data.clouds (good catch on my typo, thx) and it was returning the value null. And the 2nd one is from a different API and was returning a blank string.
Do you know if there’s another topic that shows how to use the equal block to replace the null value with “Clear” and how to handle a blank string? If so, will you point me in their directions, please?
I added error checking because it’s important to do that when using an API, especially because attempting to parse JSON data that doesn’t exist can crash an app. But for testing, you could certainly leave that out if you prefer.
P.S. The test block is kind of fun to use once you get used to Thunkable more. You can use it to make more efficient code – or at least to reduce the number of blocks needed. Here’s another way to do the same thing as above: