Slashes in json returned from node
<p>I am getting slashes in the json returned from Node server. This is giving challenges in parsing the json.</p>

<p>The json looks like</p>

<pre><code>"{\"responseCode\":200,\"headers\":{\"Access-Control-Allow-Origin\":\"*\",\"Content-Type\":\"application/json; charset=utf-8\",\"X-Powered-By\":\"Express\",\"Connection\":\"keep-alive\",\"Date\":\"Thu, 22 Sep 2016 08:12:39 GMT\",\"Content-Length\":\"21\",\"Etag\":\"W/\\"15-HeifZ4bmt+WxpIWDoartGQ\\"\"},\"response\":\"{\\"status\\":\\"UP\\"}\",\"bytesSent\":715779}"
</code></pre>

<p>In order to get rid of the slashes, I did a replace and then converted it back to json using JSON.parse</p>

<pre><code>.then(function (result) {
     var status = "";
     var str = JSON.stringify(result); 
     console.log("str result  ", str);
     str = str.replace(/\\/g, "");
     console.log("result after cleanup  ", str);
     var obj = JSON.parse(str);
     status = obj.response.status;
}
</code></pre>

<p>After replacing the slashes, the string looks like this</p>

<pre><code>"{\"responseCode\":200,\"headers\":{\"Access-Control-Allow-Origin\":\"*\",\"Content-Type\":\"application/json; charset=utf-8\",\"X-Powered-By\":\"Express\",\"Connection\":\"keep-alive\",\"Date\":\"Thu, 22 Sep 2016 08:12:39 GMT\",\"Content-Length\":\"21\",\"Etag\":\"W/\"15-HeifZ4bmt+WxpIWDoartGQ\"\"},\"response\":\"{\"status\":\"UPLOADED\"}\",\"bytesSent\":715779}"
</code></pre>

<p>When I try to parse it to JSON object, it throws an error on </p>

<pre><code>var obj = JSON.parse(str);
</code></pre>

<p>It seems that the JSON is still invalid due to the slashes which still exist. </p>

<p>I have the following queries -</p>

<ol>
<li>How can I update my regex to get rid of these slashes as well</li>
<li>Why do these slashes get introduced in the response</li>
</ol>