I’m trying to detect if a JSON string exists (i.e. not null) and send an empty json object {}
instead.
First, I use Transform to JSON to turn an object into JSON
Then, I use an if statement to check if the object exists or not
But it’s still being sent as null
PS, I’ve tried using three different approaches to detect null: null
, "null"
and backticks.
Hello,
can you try with emptystring
in your comparison (instead of null
) to see if it works?
![image](https://europe1.discourse-cdn.com/business20/uploads/make/original/3X/a/b/abdbbcc6b55a95323beec9d3872bcd8a37232cd2.png)
Benjamin
2 Likes
Thanks for the suggestion, but that didn’t work. I’ve also tried {{ifempty(8.json; "{}")}}
, but this also didn’t work.
Hmm, I don’t think you can validate the JSON directly, because it either outputs a valid JSON or throws an error.
If it throws an error, you can simply use a Resume directive to return {}
(empty JSON object string).
If you need further assistance, please provide the following:
- An example of invalid “4.timeSpend.timePerWeek” variable (the output bundle of module [4])
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
I’m not getting any errors on the Transform to JSON step. It’s either returning valid JSON, or null as shown in this image.
It’s not the end of the world, I’ll just need to check for null
at the other end.
Since the output is “null” (a string), not null
(a special variable with pink background),
Then you should convert the null
in your third screenshot above to “null” (text WITHOUT pink background).
This image’s null
should be manually typed in as “null” (without double quotes).
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
1 Like
I’ve tried each of the following, but none work.
I was able to make it work with the inverse:
Output 1
![Screenshot_2024-06-19_200616](https://europe1.discourse-cdn.com/business20/uploads/make/original/3X/e/1/e1ff55260efd8359941500b6b3169ff807e1ad41.png)
Output 2
![Screenshot_2024-06-19_200637](https://europe1.discourse-cdn.com/business20/uploads/make/original/3X/e/a/eac11a696703d4146ad76f693135baadbfeb4874.png)
samliew – request private consultation
Join the Make Fans Discord server to chat with other makers!
1 Like
I will give that a try, thank you. Annoyingly, my dataset now doesn’t have any null values, so I’ll need to wait until I get some.
I can confirm at the very least that the json string is coming though correctly still, however, so I"ve got a good feeling about this one. It’s weird if it works this way around, but not the other.
Thank you for your help.