How to resolve Illegal unquoted character ((CTRL-CHAR, code 10)) error

I have one flow which is getting the messages from the Crisp chat via Api for that i used
this endpoint “/messages?limit=20&order=desc“ and i m getting the response in output => body => data => collections now i want to send this all collections as one string in HubSpot notes so for that i was trying to use “create a note“ module which is already provided but I m facing scope permission issue so i try to make API call and currently i am using “http make request” module and in this i have set all the require properties and timestamp etc. but when i get the collections after that sending all that data in one string i used “iterator” module after that i used “text aggregator” module to format that data and sending into one string

and this is formatting the text as well but when i used this in my final module for making API call i am facing this error

Error: 400 Bad Request

  • {“status”:“error”,“message”:“Invalid input JSON on line 3, column 820: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value”,“correlationId”:“691dc311-0000-0000-2b73-8510d2c51ab0”}

    in my final step i did this

{
“properties”: {
“hs_note_body”: “{{replace(19.text; “\n”; “\n”)}}”,
“hs_timestamp”: {{timestamp}}000
},
“associations”: [
{
“to”: {
“id”: “{{12.id}}”
},
“types”: [
{
“associationCategory”: “HUBSPOT_DEFINED”,
“associationTypeId”: 202
}
]
}
]
}

i want a new row for each message too but because of this error i removed new row separator from the aggregator and i m stuck here from last 2 days

Hey there,

You can use the replace() function to escape special characters. Check your incoming string for what specifically is breaking the JSON and escape it. Or you can try something like this.

Hey ,

Thank you for reply and in text aggregator module output i am getting like this


and i guess the spaces after “respond within 10 min” text is creating a issue and replace function is not much helpful .

Welcome to the Make community!

This is NOT sufficient to convert text to an escaped (safe) JSON string.

Escaping strings before mapping into another JSON string

Most of the time, you cannot directly map variables containing text content into another JSON string without escaping them, as the variable might contain special characters that are reserved. Special characters in JSON needs to be escaped (encoded) as a “literal” character, otherwise they make the whole JSON invalid when you map the variable value when creating another JSON string.

You can escape string variables by passing the text into the “Transform to JSON” module. You can also build a valid JSON string by using a Data Structure with the “Create JSON” module. Then, you can map the output of the Transform module into another JSON string, or simply use the whole output of the Create module.

:warning: Note:

When using the “Transform to JSON” module, the output should already contain the double quotes " " around your text, so when you map this output into your JSON, you should not need to wrap another pair of double quotes around it.

Alternatively, you can use the built-in function replace to replace those special characters with their escaped versions. To do this, simply paste this into the field, and replace the 1.text variable:

{{ replace(replace(1.text; "/([""\\])/g"; "\$1"); "/\r?\n\r?/g"; "\n") }}

For more information on JSON and escaping JSON strings, see:

Hope this helps! If you are still having trouble, please provide more details.

@samliew
P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!

2 Likes

Yup “Transform to JSON“ module works for me. Thank you so so much @samliew :innocent: .

1 Like