Wrapping JSON strings in quotes for API connector

I’m struggling to find a good way to pass strings as JSON. Currently the JSON body in my api connector looks something like this { "firstName": "<firstName>", "lastName": "<lastName>"} First name and last name are obviously strings, so I am wrapping them in quotes.

The issue is that if one of these values is empty, Bubble will return null, and the JSON will have the word null wrapped in quotes, as a string.

I see two options:

  1. Don’t wrap in quotes. This allows us to pass actual null values, but will cause a JSON error if the string has a space in it, so not a valid solution.
  2. Create a new step to populate every single field in the api call using it’s own when statement, and add the quotes to the string there if it is not empty

Option 2 would work, but with dozens of api calls with dozens of fields each, it’s a bit ridiculous. Does anybody have a better, maybe more scalable solution?

Try to populate with a default at app level with " " (empty space), for example a custom state of the text type.

@jkeirle Were you able to solve this issue?

1 Like

Hey Mo!

Leaving the value without quotes in the API connector should be ok. In the place inside the app where the string is actually sent, you can have a condition like the following:

[This object] is not empty: formatted as text

The condition for “yes” would include quotes (around a string associated with the object), and the condition for “no” would be the text null.


1 Like