We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Replace '\' with '\\'

Cindy Sim
Tera Expert

I need to replace '\' with '\\'. How can we do it? Currently I am using :

replace("\", "\\"));
10 REPLIES 10

This payload is not value.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

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);

Mark the response correct and helpful if the answer assisted your question.

Sandeep Rajput
Tera Patron

@Cindy Sim This works just fine 

replace("\", "\\"));
 

var a = vString;

a = a.replace('\', '\\'); 

this is now working 

I have tested it and it works fine.