# Http response, json without backslashes

**URL:** <https://discourse.nodered.org/t/http-response-json-without-backslashes/19376>\
**Category:** General\
**Created:** [20 December 2019 09:05 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376 "2019-12-20T09:05:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 09:05 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/1 "2019-12-20T09:05:45Z")

</div>

Hi, I try to make simple API for mssql database and I get it working. MSSQL return JSON directly nicely with "FOR JSON PATH"

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d9619c900d74768b4a93807699bd9094af711e88.png)

But response is escaped with backslashes, how I can removed those backslashes?

```auto
"{\"ProductCode\":\"0040001\",\"ProductName\":\"Brother DK11209 osoitetarra 29x62mm\"}"

```

I need response to be like

```auto
"{"ProductCode":"0040001","ProductName":"Brother DK11209 osoitetarra 29x62mm"}"

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 December 2019 09:29 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/2 "2019-12-20T09:29:38Z")

</div>

Hi @timnis

Where are you seeing those backslashes?

Have you added a Debug node to see exactly what you are passing to the HTTP Response node?

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 15:18 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/3 "2019-12-20T15:18:18Z")

</div>

@knolleary sorry for late answer.

Debug node shows json without backslashes, but if I test with firefox or Postman I see backslashes. In

I running NR on docker (official latest).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [20 December 2019 15:35 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/4 "2019-12-20T15:35:09Z")

</div>

Can you show us what the debug node shows. You say it shows JSON, which implies that it is a string, but if it is a string then you need the escaped inner quotes.

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 15:44 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/5 "2019-12-20T15:44:10Z")

</div>

Sure, here it is

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/ff749c2472c291ae83a0d655efa811ee87acc160.png)

And same time Postman shows

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b20f29ce489d88257db216c6f5e72a6c0a88d0fb.png)

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 15:50 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/6 "2019-12-20T15:50:18Z")

</div>

here is export of it

[{"id":"56854e06.f4b4e8","type":"http in","z":"710faa96.defddc","name":"","url":"/testi/:code","method":"get","upload":false,"swaggerDoc":"","x":110,"y":240,"wires":[["e116542b.46ac18"]]},{"id":"e116542b.46ac18","type":"MSSQL","z":"710faa96.defddc","mssqlCN":"5def4f8f.da2d1","name":"","query":"SELECT v.KOODI AS ProductCode, \nv.NIMIKE AS ProductName\nFROM VARASTO v \nWHERE v.KOODI = '{{{req.params.code}}}'\nFOR JSON PATH, without\_array\_wrapper, INCLUDE\_NULL\_VALUES","outField":"payload","returnType":0,"throwErrors":1,"x":300,"y":240,"wires":[["8dbdeeba.c14ad","57c0287.3fb52d8"]]},{"id":"8dbdeeba.c14ad","type":"http response","z":"710faa96.defddc","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":530,"y":240,"wires":},{"id":"5def4f8f.da2d1","type":"MSSQL-CN","z":"","tdsVersion":"7\_4","name":"vm","server":"172.19.0.4","port":"1433","encyption":true,"database":"YR1","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"}]

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 December 2019 16:25 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/7 "2019-12-20T16:25:08Z")

</div>

@timnis postman shows that because you are returning a JavaScript Object with a key of `JSON_F525....` and a value that is a JSON String. You know it is a string because it is surrounded by `"` and to keep it a valid string, the inner `"` have been escaped with the backslash.

So the answer here is to parse the JSON string value of the `JSON_F525...` property before returning it. You can use the JSON node to do that.

Btw, when you share flow JSON, please make sure you use the `</>` button in the formatting toolbar to format it properly, otherwise the forum will badly format your JSON and make it impossible to import.

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 16:43 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/8 "2019-12-20T16:43:18Z")

</div>

@knolleary Thanks, I added JSON node just before http response and selected "Always convert to JSON Strings" but it won't help. What I did wrong?

Now I have

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/da42a4f643a449cdfce46d278a1ef769bf5452da.png)

Export below

```auto
[{"id":"ed775a11.702ec8","type":"http in","z":"9655b2c6.4f50b8","name":"","url":"/testi/:code","method":"get","upload":false,"swaggerDoc":"","x":110,"y":240,"wires":[["ce848e27.cbee38"]]},{"id":"ce848e27.cbee38","type":"MSSQL","z":"9655b2c6.4f50b8","mssqlCN":"e9370435.63fbb8","name":"","query":"SELECT v.KOODI AS ProductCode, \nv.NIMIKE AS ProductName\nFROM VARASTO v \nWHERE v.KOODI = '{{{req.params.code}}}'\nFOR JSON PATH, without_array_wrapper, INCLUDE_NULL_VALUES","outField":"payload","returnType":0,"throwErrors":1,"x":380,"y":240,"wires":[["3be57d05.0011ba"]]},{"id":"d905e261.dc224","type":"http response","z":"9655b2c6.4f50b8","name":"","statusCode":"","headers":{"content-type":"application/json"},"x":870,"y":240,"wires":[]},{"id":"b5693abb.e7eca8","type":"debug","z":"9655b2c6.4f50b8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":870,"y":320,"wires":[]},{"id":"3be57d05.0011ba","type":"json","z":"9655b2c6.4f50b8","name":"","property":"payload","action":"str","pretty":true,"x":590,"y":240,"wires":[["d905e261.dc224","b5693abb.e7eca8"]]},{"id":"e9370435.63fbb8","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"vm","server":"172.19.0.4","port":"1433","encyption":true,"database":"YR1","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 December 2019 16:47 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/9 "2019-12-20T16:47:56Z")

</div>

You have the JSON node configured to parse `msg.payload`. But from the postman screenshot you shared, the property that needs to be parsed is `msg.payload[0]["JSON_F52E2B........."]`.

So the question is whether that is _always_ the property you want to parse, or does the `JSON_F52E2B...` key change depending on the query you are running? If so, you'll need to use a Function node to pull apart the response of the SQL node and parse the appropriate part.

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 17:07 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/10 "2019-12-20T17:07:59Z")

</div>

Its looks like to be always same if you use mssql server 2016 or 2017 with JSON feature.

More info

> <https://github.com/tediousjs/node-mssql/issues/209>
>
> In Sql Server 2016 CTP2 is added FOR JSON query clause that formats result set of T-Sql query as JSON text...

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 17:11 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/11 "2019-12-20T17:11:56Z")

</div>

here is more accurate info

> **[node-mssql](https://tediousjs.github.io/node-mssql/#json-support)**
>
> Microsoft SQL Server client for Node.js

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [20 December 2019 17:15 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/12 "2019-12-20T17:15:17Z")

</div>

Hi @timnis - so if you change the JSON node to parse `msg.payload[0]["JSON_F52E2B61-18A1-11d1-B105-00805F49916B"]` then you should be all set.

---

<div class="post-metadata">

**Author:** ![timnis](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@timnis](https://discourse.nodered.org/u/timnis)\
**Post date:** [20 December 2019 18:26 UTC](https://discourse.nodered.org/t/http-response-json-without-backslashes/19376/13 "2019-12-20T18:26:14Z")

</div>

@knolleary Thanks.

I tested to add config option to nodes config and it worked, directly like it should. So I ended up opening issue for the problem.

[https://github.com/bestlong/node-red-contrib-mssql-plus/issues/20](https://github.com/bestlong/node-red-contrib-mssql-plus/issues/20)
