code: protected function buildJSonResponse($value, $status = 200)
      {
          if (is_array($value)) {
              $value = json_encode($value);
          }
          $response = new Response($value, $status);
          $response->headers->set('Content-Type', 'application/json');
  
          return $response;
      }
docs: Builda a json response
  @param mixed $value
  @param int $status
  
  @return \Symfony\Component\HttpFoundation\Response