<?phpuse Symfony\Component\HttpFoundation\JsonResponse;// use fitting Symfony response classes$data = [ 'data' => ['foo', 'bar', 'key' => 'value']];$response = new JsonResponse($data);$response->sendContent();