JsonResponse - Symfony has a lot of different Response classes

Code
<?php

use Symfony\Component\HttpFoundation\JsonResponse;

// use fitting Symfony response classes
$data = [
    
'data' => ['foo''bar''key' => 'value']
];
$response = new JsonResponse($data);
$response->sendContent();
Result
{"data":{"0":"foo","1":"bar","key":"value"}}