Replace single backslash with double. How does it effect string that already have double backslah
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2019 12:20 AM
Hi ,
I'm using the below code to escape single backslash that is present in my JSON payload
json_payload.replace("\\","\\\\");
This works fine when the payload contains single backslash. eg {"name": "\xyz"}
This gets converted to {"name": "\\xyz"}
but the cases where there are 2 backslash already {"name": "\\abc"} the output is {"name": "\\\\abc"}
As far a I know as backslash is special character in JS, we need to escape each single (\) with double(\\), and that is what my code does, why does it effect the already double(\\).
Nisha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2019 11:19 AM
Hi asifnoor,
It did not work. Still getting 4 backslash if 2 are present in JSON. Could you tell me how the code given by you works?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2019 11:47 AM
can you share your json once.