Bad control character error when JSON payload contains line breaks

:bullseye: What is your goal?

Process incoming webhook data and generate a PDF via APITemplate.io,
including a multi-line text field (“informe” / report) in the PDF.

:thinking: What is the problem & what have you tried?

My scenario is: Webhook → Google Sheets → Tools → APITemplate.io

The last module (APITemplate.io) fails with this error:

[400] Invalid JSON data: SyntaxError: Bad control character in string
literal in JSON at position 506 (line 16 column 77)
Code: RuntimeError

The problem is that one of my incoming webhook fields (“informe”)
contains actual line breaks (multi-paragraph text). This breaks the
JSON body that Make sends to APITemplate.

My Payload Type is set to “Dynamic Data (JSON Payload)”.

I tried wrapping the variable inside the JSON field like:
“informe”: “{{replace(1.informe; newline; “\n”)}}”
but I’m not sure if this is the correct syntax.

Question: what’s the correct way to escape line breaks inside the
JSON body without switching to Key Value Pairs? What’s the exact
syntax for the replace() function inside a JSON field?

Thanks!

:clipboard: Error messages or input/output bundles

[400] Invalid JSON data: SyntaxError: Bad control character in string literal in JSON at position 506 (line 16 column 77)
Code: RuntimeError

Hey there,

The forum here changes formatting for Make formulas so copy pasting them here directly doesn’t work.

In general that is the correct syntax but you should use the newline variable from the menu and not the literal string newline.

Make now has an escapeJSON() function, so you can avoid manually replacing only the newline character (which would still fail if the report contains quotes or backslashes).

For a raw JSON body, keep the outer JSON quotes and map the field through the function:

"informe": "{{escapeJSON(1.informe)}}"

Insert the mapped informe token from the mapping panel inside escapeJSON(...); do not type 1.informe literally if your module number differs. This escapes line breaks, quotes, and backslashes together.

An even safer alternative is JSON > Create JSON with informe defined as a text field, then map its output to the API module instead of hand-building JSON. Test with two paragraphs plus a quoted phrase; if that works, the payload is being escaped correctly. Avoid applying both methods at once, or the text may be double-escaped.