Flow Designer REST step JSON parsing error due to newline (\n) in script output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2026 12:54 PM
Hi All,
I'm facing an issue in Flow Designer when passing a value from a Script step into a REST step.
I am building a string using incident task fields like below:
var summary = fd_data.subflow_inputs.incident_task.description + "\n" +
fd_data.subflow_inputs.incident_task.number;
Return summary:
This value is then used in the REST step request body.
However, whenever the string contains a newline (\n), the REST step fails with the error:
"There was an error parsing JSON. Check that your request body is valid."
If I remove the newline, it works fine.
Questions:
1. How should newline characters be handled in Flow Designer when building JSON payloads?
2. Should the newline be escaped differently (e.g. \\n)?
3. Is there a recommended way to safely pass multi-line text to REST APIs from Flow Designer?
Any guidance would be appreciated.
Thanks!
Ravish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2026 04:09 PM
There are a few control characters that need to be escaped for valid json. You can use the glidestringutil api. Or just use the json builder step in your action
GlideStringUtil.escapeNonPrintable("a\n\t\b\''''")You can also use the transform functions on data pills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2026 08:02 PM
you can either replace those or try to use JSON.stringify()
share your complete code here
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2026 08:59 PM
Use the built-in JSON.Strinfy() method.
Sample code:
var reqPayload = {
"fieldName": "Line 1\nLine 2"};
var jsonReqPayload = JSON.stringify(reqPayload);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi Ravi,
Just add two lines of code after declaring summary,
Existing one:
var summary = fd_data.subflow_inputs.incident_task.description + "\n" +
fd_data.subflow_inputs.incident_task.number;
Extra added code:
summary = JSON.stringify(summary); //converts String to JSON String.
summary=summary.slice(1,-1); //removes extra quotes added by .stringify();
Note:
Also check, usually in payloads summary should be in single-line text, not multi-line text. Only description can be allowed to send as multi-line text.
3. Is there a recommended way to safely pass multi-line text to REST APIs from Flow Designer?
You can also try JSON Builder Step in flow designer Actions for generating payloads. It is very easy and you can avoid all these coding stuffs and newline issues etc.,
click on "Add new step" look for "JSON Builder" and then click on "Add JSON for payload" enter your payload and click "Generate JSON payload" just drag and drop you action input under "summary" the payload is ready.
Now in "REST Step" under "Request body" use "Data Pill" to add your payload.