Inserting dynamic multiline input text into JSON API body without breaking JSON

Hey everyone, I am building an app and have an Anthropic API call set up and working perfectly with hardcoded text in the body. I am now trying to make it dynamic by inserting text from a Multiline Input element into the JSON body.

I have added<contract_text>as a parameter placeholder in my API body like this:

“content”: “CONTRACT TEXT: <contract_text>” In my workflow Step 2 (the API call) I set contract_text = Multiline Input A’s value dynamically.

When I run it I get a HTTP 400 error: “The request body is not valid JSON: unexpected content after document”

I believe the issue is that the pasted text contains special characters like apostrophes, line breaks and quotes that are breaking the JSON structure when inserted dynamically.

Questions:

  1. Is there a way to sanitise or escape the text before it is inserted into the JSON body?

  2. Should I be using the Toolbox plugin to build the JSON body dynamically instead?

  3. Is there a better pattern for sending large blocks of user-inputted text to an external API via Bubble?

Any help appreciated — the API call itself works perfectly with static text so this is purely a dynamic insertion problem

Multiline Input A’s value:formatted as JSON-safe

Take note that formatted as json safe will also add doubles quotes around string so you need to remove it from API connector payload

Thanks!
do you know if formatted as JSON-safe is only be available in Bubble’s classic editor? I can’t see it.