Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chapdel's avatar
Level 24

How to solve Laravel JSON response formatting problem

I'm in big trouble here! In fact, with Laravel I generate a url that I return as an answer. But the problem is that the returned URL contains double backslashes. Like http://localhost:8003/book?key=4fCNcwyuWJgn8LQN and yet I want to have it in the form http://localhost:8003/book?key=4fCNcwyuWJgn8LQN.

I return the url as php return response()->json([url => $url]); and before the response I get http://localhost:8003/book?key=4fCNcwyuWJgn8LQN but the response I get is http://localhost:8003/book?key=4fCNcwyuWJgn8LQN

0 likes
6 replies
bugsysha's avatar

If you check both cases have the same URL's. Maybe you should post a screenshot.

bugsysha's avatar

@chapdel and what do you get when you use that value? I'm pretty sure it will be "normal". That is just displayed like that to avoid escaping characters.

nodenacci's avatar

Hi, use php stripcslashes($yourURL) function that strips out those escape characters.

example

$url = "http:\/\/localhost:8003\/\/book?key=4fCNcwyuWJgn8LQN.";
// http:\/\/localhost:8003\/\/book?key=4fCNcwyuWJgn8LQN

$stripped_url = stripcslashes($url);
// http://localhost:8003//book?key=4fCNcwyuWJgn8LQN.
1 like
JohnnyBigodes's avatar
Level 13

That is perfectly normal in Insomnia.

It escapes all backslashes.

I know this is not the answer you want to hear, but using Postman you dont have this problem.

1 like

Please or to participate in this conversation.