Escaping quotes in JSON

Hi everyone,

we have connected an API to our app that takes user input text in JSON format. The problem is that any quotes or double quotes in the user input end the request and cause an error. Does anyone know a solution for this?

Thanks in advance!

there’s a function :formatted as json_safe

Thank you!!

1 Like

Hi. I recently faced a similar issue were :formatted as json_safe didn’t do the trick.
I used instead “find & replace” to remove the quotation marks from the user’s input.

Hope it helps someone in the future.

JSON safe do the trick… if you use it correctly

When I read this comment from a Bubble Certified developer… this raise doubt on this certification…

1 Like

I’m unsure about that. Using Openai’s responses api when Usin JSON-safe.. in the “input” field the call didn’t even reached out. I used this post as reference as well.

You can send it to a back-end workflow, and then return the response in content-type other. It will return structured JSON.

Did you read:

And the rest of the same reply.

JSON-safe is safer for all JSON enconding. This is the function to use, not find and replace.

Seems there is a bug in bubble formatted as json safe



@Jici is the above what you experience using the double quotes in an input element and formatted that input element value into json safe? I believe what I am seeing is a bug and the json safe is not working properly on the double quotes…but of course that could be me not understanding the correct expectation and maybe it is doing what it is supposed to, which is retains the double quote from the input element value but it formats it so that it is JSON Safe.

Based on chat GPT there is no bug in the formatted as JSON safe and it is properly formatting the input value with double quotes into a JSON safe format.


So perhaps @ramaarana7 is expecting that the format as JSON safe will STRIP AWAY the double quotes, which is not what formatted as json safe operator is designed to do, and instead it is designed to take any value with or without double quotes and ensure that full value is formatted to be JSON safe.

So, if the goal is to remove the double quotes from the Open AI response, than formatted as JSON safe is not the correct operator, because it is not meant to remove double quotes. BUT if the goal is to retain the double quotes and ensure you can pass that value safely with JSON array, than the formatted as JSON safe is the correct operator and it is doing what it is supposed to do.

The goal of json-safe function is to keep the integrity of the string and escape everything that need to be escaped like double quotes, backslash, newline and put this into a string properly encoded with double quotes surrounding it so the string will not break json. This is what is expected yes and there’s no bug.

The only reason to use a find and replace is if the API itself expect a string without any special character, but this is not because it will break the json, but because the API server doesn’t accept them (some old system for example will not accept modern encoding for example)

1 Like

Also, we are not talking about the open AI response, but the open AI request sent to API like the screenshot of @ramaarana7 show