0

in SQL server data is showing in this form

{"whiteList":[{"url":"https:\/\/www.google.com","type":"exact","status":"1","id":"1573023904"}]}

why extra backslash is added in url?

Method that i used in laravel controller to store data is json_encode($arr);

Zain
  • 452
  • 5
  • 14
  • What extra backslash? There are 2 backslashes (which is correct, to escape the 2 forward slashes), not 3. – Thom A Nov 06 '19 at 12:49
  • @Larnu I think the question is _why_ the forward slash is being escaped. – IMSoP Nov 06 '19 at 12:51
  • Your first step should be to confirm where the backslash is being added. Is it there when you call `json_encode` but before you put it into the database? If so, you don't need to talk about SQL Server here. On other hand, if it's _not_ there before you put it into the database, you don't need to talk about Laravel and `json_encode`. – IMSoP Nov 06 '19 at 12:53
  • Statement `json_encode($arr, JSON_UNESCAPED_SLASHES)` is probably a possible explanation here. – Zhorov Nov 06 '19 at 12:53
  • I just want to know that, is it because of json_encode() method or something by SQL server ? – Zain Nov 06 '19 at 12:57
  • because I have to store data in JSON encoded form is SQL – Zain Nov 06 '19 at 12:58
  • SQL Server *does* escape forward slashes when creating JSON, yes @Zon. The linked duplicate suggests about .Net applications (SQL Server didn't support JSON when the answer was written) doing so, and it can be seen [here](https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=c7d58cc558e5dea1c3dd363a071629a2). That, however, doesn't mean it's not Laravel doing it. We don't have enough information to know. – Thom A Nov 06 '19 at 12:59
  • 1
    @Zon It's really really easy for you to find out if it's Laravel or SQL Server doing it: `echo` the value in Laravel; and manually insert some data in SQL Server (e.g. using SQL Server Management Studio). – IMSoP Nov 06 '19 at 13:13

0 Answers0