0

It is my first time to use Mysql json column type when I make post request via Laravel api to make new user like this

"username:andy21, password:123456, profile:{"home_town":"germany"}"

I save profile in the Json column when I retrieve it, it have backslash before every " on the json object like this

"profile":"{\"home_town\":\"germany\"}"

my return in laravel controller looks like this

return response()->json(['profile'=>$user]);

why it have these backslashes and how to remove it ?

3
  • 1
    How about the value on the database? Is it backslashed? Commented Dec 15, 2016 at 20:54
  • Same as I have sent it, I think it maybe because of the json respons in laravel Commented Dec 15, 2016 at 21:04
  • I wrote the answer. Commented Dec 15, 2016 at 21:06

1 Answer 1

2

Try this, if your $user variable is in JSON format:

return response()->json(['profile' => json_decode($user)]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.