Symfony JsonResponse with Serializer

The object is encoded twice because you use a jsonresponse, use a simple response instead. In addition encode the entire data, not only part of them . As example:

$responseData = [
    'status' => true,
    'data'   => $post
];

$response = new Response(
   $serializer->serialize($$responseData, 'json'),
   Response::HTTP_OK,
   ['Content-type' => 'application/json']
);

return $response:

Hope this help


To return a json string instead of an array use the JsonResponse::fromJsonString method:

return JsonResponse::fromJsonString($serializer->serialize($data, 'json'));

Tags:

Php

Json

Symfony