从Laravel中的JSON字符串中删除添加的反斜杠

So I'm trying to store some HTML code in the database and then retrieving it througth the API.

Initial HTML:

<img src="https://www.google.se/images/google_80w1ht.gif" alt="Google logo">

Then I store in the DB without any further hassle:

$data = $request->only(['content');

$comment = $this->repo->update($data, $id);

If I go to MySQL Workbench, this is the data stored:

<img src="https://www.google.se/images/google_80wht.gif" alt="Google logo">

However, the moment I retrieve it want want to output the HTML as a JSON parameter, it get's slahed all over the face.

This is the json:

{"title": "<img src=\"https://www.google.se/images/google_80w1ht.gif\" alt=\"Google logo\">"}

I have not applied any transformation nor during insert nor on retrieval.

How can I remove the added extra backslashes? ()

Try json_decode(your_data) this should work.

I have not applied any transformation nor during insert nor on retrieval.

You converted it to JSON. That is a transformation.

it get's slahed

The slashes are needed.

Without them this happens:

"<img src="h
^         ^^
|         ||
|         |Error
|         End of string
Start of string

The data doesn't contain the slashes, just the JSON representation of it. When you parse the JSON the escape sequences will be consumed and you will get your original string back.