0

I have this object that I send in response as json.

{"__type":"http:\\/\\/example.com\\/contracts\\/documents\\/rendering\\/instructions\\/1\\/0"}

I want response to be:

{"__type":"http:\/\/example.com\/contracts\/documents\/rendering\/instructions\/1\/0"}

but I get this:

{"__type":"http:\\/\\/example.com\\/contracts\\/documents\\/rendering\\/instructions\\/1\\/0"}

How do I escape string correctly, so I can get response string with only one backslash?

Temo
  • 11
  • 3
  • 2
    Why do you escape the string to begin with? `"http://example.com/contracts/documents/rendering/instructions/1/0"` is valid JSON, so why escape the `/` before you actually need it to be escaped? – Shilly Apr 18 '19 at 12:03
  • A [mcve] might make this easier to understand. It's really not clear what is an object or what is JSON. – Quentin Apr 18 '19 at 12:04

1 Answers1

0

Do this:

let str='{"__type":"http:\\/\\/example.com\\/contracts\\/documents\\/rendering\\/instructions\\/1\\/0"}'
let result = str.replace(/\\/g,'\\');
Pratyush Sharma
  • 207
  • 3
  • 7