@samirapadidar I have surprise for you: json is a string!
for example
'{foo:"bar"}'
it's string, but contains correct json data which can be parsed and processed
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I was trying to convert an array to json and this is my code
private function prepareLogData(Request $request)
{
return json_encode([
'ip' => $request->ip(),
'url' => $request->url(),
'agent' => $request->userAgent(),
'date' => Carbon::now()->toDateTimeString(),
'params' => $request->query(),
]);
}
But then when I tested the output of this code, I realized that it returns a string. this is my code
dd(is_string(json_encode([
'ip' => $request->ip(),
'url' => $request->url(),
'agent' => $request->userAgent(),
'date' => Carbon::now()->toDateTimeString(),
'params' => $request->query(),
])));
return the true output how can convert this array to json???
Please or to participate in this conversation.