Replace '\' with '\\'
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:14 AM
I need to replace '\' with '\\'. How can we do it? Currently I am using :
replace("\", "\\"));
10 REPLIES 10
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 10:56 AM
This payload is not value.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 11:32 AM
Hi @Cindy Sim ,
Try the below script:
var json2 = "{\"firstName\":\"John\",\"lastName\":\"Doe\",\"executiveSummary\":\"Below, you will find a proposal, etc. etc.\",\"products\":[{\"name\":\"test product\",\"quantity\":5,\"price\":10,\"total\":50},{\"name\":\"Creatice Name\",\"quantity\":10,\"price\":20,\"total\":200}]}";
var replaceJson = json2.replace(/\\/g, '\\\\');
gs.info(replaceJson);
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:30 AM
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:35 AM
var a = vString;
a = a.replace('\', '\\');
this is now working
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:37 AM
I have tested it and it works fine.