for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class LuckyControllerJson
{
#[Route("/api/lucky/number")]
public function jsonNumber(): Response
$number = random_int(0, 100);
$data = [
'lucky-number' => $number,
'lucky-message' => 'Hi there!',
];
// return new JsonResponse($data);
$response = new JsonResponse($data);
$response->setEncodingOptions(
$response->getEncodingOptions() | JSON_PRETTY_PRINT
);
return $response;
}