Hello Bubble Community,
I’m building a document generator app that interacts with the OpenAI API to produce custom policies based on user input. Users provide data through various text input fields (e.g., company name, business activities), which can contain any range of characters, including special ones like quotes and newlines. This user-provided data is then used to construct a JSON payload for the API call.
-
Purpose of the API Call:The API call takes the user input and uses it to generate a tailored document. The inputs are sentences and phrases that describe aspects of the user’s company and its information security practices.
-
Issue Encountered:I’ve encountered JSON invalid errors (error 404) when the user input includes special characters (my API call usually works). To combat this, I’ve tried using Bubble’s
:formatted as JSON-safeoperation on the input fields. It appears that this fix leads to a malformed JSON and an invalid API call. -
Example Error:Invalid JSON error, usually indicating a parse error where it’s expecting EOF, ‘}’, ‘:’, ‘,’, ‘]’, got ‘undefined’.
I believe applying:formatted as JSON-safe to each input field would solve the issue, but this systematically leads to HTTP 400 error. I suspect the function may be misused, or there’s a better way to sanitize the inputs that I’m not aware of. Here are the server logs:

Could someone advise on the best practices for sanitizing user input in Bubble for JSON payloads… in my specific use case? Specifically, how can I ensure that the dynamic data entered by users is automatically processed so that it doesn’t disrupt the JSON structure (so the doc generation process will work), while also keeping the process efficient and not overly complex?
Any insights, workflows, or plugins that could help with this situation would be greatly appreciated. I aim for a solution that is automated and reliable, with a success rate of 99.99%.
Below some screenshots of my input fields and API call and error in Json inspector.
User inputs
Formatted json safe

How it looks in server logs

Error
Thank you for your time and assistance!

