- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 03:36 AM
Hi ,
I have to replace all occurances of \" , "{ and "} from response of API. I am using replaceAll function of string as below but it is not working
var str2=responseBody.toString().replaceAll('\"','"');
var str3=str2.replaceAll('"{','{');
var str4=str3.replaceAll('"}','}');
This is not replacing these char , Please let me know how can we replace all chars as required.
Thanks
Deepak
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 09:36 PM
Hi Deepak,
Can't replace backslash because it's an escape character. Backslash and the next character will be treated as 1 character in JavaScript. This is JavaScript specification.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 09:38 PM
For example, the length of string '\"' is 1 and not 2.
var str = '\"';
gs.info('length:' + str.length);
Execution result:
*** Script: length:1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 10:07 PM
Hi
Is it possible to share the payload that you are receiving?
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2022 10:29 PM
Hi
You can try below-provided logic:
var str = 'This is test \"value inside double quotes\" and opening curly braces "{ with closing curly braces "}';
str = str.replace(/\","/g);
str = str.replace("\"{","{");
str = str.replace("\"}","}");
console.log(str);
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2023 10:55 AM
Hi Deepak, did you find any resolution to this. I am in the same where I am trying to parse my input json file but failing as I am unable to trim escape sequence.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2023 10:08 AM
Hi,
I used replace function as below:
.replace(/\}"/g, '}')
you can refer javascript replace function for escape sequence.