ServiceNow Data Action Failing When Incident Short Description Contains Double Quotes

I have configured Data Action to create ServiceNow incidents from Architect flow. It is working for most calls but failing intermittently. After investigating, I found that it fails whenever the agent enters double quote characters in the wrap-up notes field.

The Data Action takes the wrap-up notes from the conversation and passes it as the short_description field in the ServiceNow incident creation API.

Request template:

{
 "short_description": "${input.wrapUpNotes}",
 "caller_id": "${input.callerId}",
 "urgency": "3",
 "category": "inquiry"
}

When agent writes wrap-up notes like: Customer asked about "premium" plan pricing the Data Action fails with:

Action execution failed: Request body is not valid JSON

The double quotes inside the notes break the JSON payload. I understand the problem but I do not know how to escape the quotes within the Data Action request template. Is there built-in function for JSON escaping in Data Action templates?

This is one of the most common ServiceNow integration pitfalls! The Data Action request template does a simple string substitution - it does not automatically escape special JSON characters like double quotes, backslashes, or newlines in the input values.

There is no built-in JSON escape function in the Data Action template language. The solution is to sanitize the input BEFORE it reaches the Data Action, inside your Architect flow.

Add a Set action before the Data Action call that uses the Replace() expression function:

Set Flow.sanitizedNotes = Replace(Flow.wrapUpNotes, "\"", "'")

This replaces all double quotes with single quotes. Then pass Flow.sanitizedNotes to the Data Action instead of the raw wrap-up notes.

If you need to preserve double quotes in ServiceNow, use the JSON escape sequence instead:

Set Flow.sanitizedNotes = Replace(Flow.wrapUpNotes, "\"", "\\\"")

This replaces " with \" which is valid escaped JSON. You also need to handle newlines (\n) and backslashes the same way if agents might include those in their notes.

In our ServiceNow integration, we created a reusable Common Module flow called “SanitizeForJSON” that handles all five JSON special characters (quote, backslash, newline, tab, carriage return) in one pass.

The Replace approach works for simple cases. For a more robust solution, switch your Data Action from using a raw JSON request template to using a form-encoded request.

ServiceNow’s REST API accepts application/x-www-form-urlencoded content type in addition to JSON. With form encoding, special characters are automatically URL-encoded by the Data Action engine, so quotes and other characters do not break the payload.

Change your Data Action request:

  • Content-Type: application/x-www-form-urlencoded
  • Body: short_description=${input.wrapUpNotes}&caller_id=${input.callerId}&urgency=3&category=inquiry

This completely eliminates the JSON escaping problem. The ServiceNow API will decode the URL-encoded values correctly on their end.

From an accessibility perspective, this is also relevant because screen reader users sometimes paste text from other applications that contains hidden Unicode characters (smart quotes, em dashes, zero-width spaces) that would also break JSON parsing. Form encoding handles all of these transparently.