Returns JSON encoded response

@param array  $data   Data supposed to be returned
@param string $status Response status code
@return JsonResponse
482302
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
501151
public function asJson(array $data)
    {
        $stream = StreamFactory::string(json_encode($data));
        return new Response($stream, self::OK, ['Content-Type' => 'application/json']);
    }
482514
protected function encodeJsonSerializable(JsonSerializable $action_result, ResponseInterface $response, $status = 200)
    {
        return $response->write(json_encode($action_result))->withStatus($status);
    }
725841
public static function json($data, $status = 200, $headers = array())
    {
        $jsonHeader = array('Content-Type' => 'application/json');

        $content = json_encode($data);

        return new Response($content, $status, $jsonHeader);
    }
333905
public function found(array $data): Response
    {
        $this->response->setBody(json_encode(['data' => $data]));
        return $this->response;
    }
631382
public function json($response, $status = 200)
    {
        $this->closeTransaction($status);
        return $this->_json($response, $status);
    }
487364
public function toResponse($status = 200, array $headers = [], $options = 0)
    {
        return new JsonResponse($this->transform(), $status, $headers, $options);
    }
566103
public function streamJson(array $data = [], $status = 200, array $config = []): SymfonyResponse
    {
        return Response::stream($this->createJsonResponse($data, $config), $status, [
            'Content-Type' => 'application/json',
        ]);
    }
975838
public function response($content, $statusCode = 200)
    {
        return response()
            ->json($this->convertContent($content))
            ->setStatusCode($statusCode);
    }
1361620
protected function getSuccessResponse($data, $statusText, $headers = [])
    {
        return $this->setStatusText($this->statusTexts[$statusText])
                    ->setStatusCode($statusText)
                    ->setStatusMessage(self::SUCCESS_TEXT)
                    ->respondWithSuccessMessage($data, $headers);
    }
757161
protected function respond($event, $error, $status, $payload = [])
    {
        $response = $this->events->fire($event, $payload, true);

        $jsonApiError = new JsonApiError(str_replace('_', ' ', $error));
        $jsonApiError->setStatusCode($status);

        return $response ?: $this->response->json(['errors' => [$jsonApiError]], $status);
    }
186946
public function raw(string $data = '', int $status = 200): Response
    {
        $response = $this;

        // Headers
        $response = $response->withoutHeader('Content-Type')->withAddedHeader('Content-Type', 'text/plain');
        $this->getCharset() && $response = $response->withCharset($this->getCharset());

        // Content
        $data && $response = $response->withContent($data);

        // Status code
        $status && $response = $response->withStatus($status);

        return $response;
    }
883760
protected function jsonResponse($data = null, array $headers = array(), array $httpHeaders = array())
    {
        $headers = array_replace_recursive(array(
            'status' => array(
                'code'    => 200,
                'message' => 'OK',
            ),
            'version' => 'v1',
        ), $headers);

        $data = array(
            'headers'  => $headers,
            'response' => $data,
        );

        // Debug data
        if (Config::get('app.debug', false) && Input::get('debug', false) == true) {
            $data['debug'] = $this->debugDatas();
        }

        $response = Response::make(json_encode($data), $headers['status']['code']);

        // HTTP headers
        foreach ($httpHeaders as $k => $v) {
            $response->header($k, $v);
        }
        $response
            ->header('Content-Type', 'application/json')
            ->setEtag(md5(json_encode($data)))
        ;

        return $response;
    }
1228182
public static function json($data = array(), $status = 200, array $headers = array(), $options = 0)
  {
    $etagMatch     = false;
    $headersToExpose = array();

    if (array_key_exists('ETag', $headers)) {
      $headersToExpose[] = 'ETag';

      // Empty the data if If-None-Match header match with ETag value
      $requestEtags = IlluminateRequest::getETags();

      if ( ! empty($requestEtags)) {
        foreach ($requestEtags as $etag) {
          if ($headers['ETag'] == $etag) {
            $etagMatch = true;
            $data    = array();

            break;
          }
        }
      }

      unset($requestEtags);
    }

    if (array_key_exists('Link', $headers)) {
      $headersToExpose[] = 'Link';
    }

    if (array_key_exists('X-Rate-Limit-Limit', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Limit';
    }

    if (array_key_exists('X-Rate-Limit-Remaining', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Remaining';
    }

    if (array_key_exists('X-Rate-Limit-Reset', $headers)) {
      $headersToExpose[] = 'X-Rate-Limit-Reset';
    }

    $headers['Access-Control-Expose-Headers'] = implode(', ', $headersToExpose);

    if ($etagMatch) {
      $response = parent::make('', 304, $headers);
    } else {
      $response = parent::json($data, $status, $headers);
    }

    $response->setCharset('utf-8');

    if (array_key_exists('ETag', $headers)) {
      $response->setCache(array(
        'etag' => $headers['ETag']
      ));
    }

    return $response;
  }
451118
protected function prepareHttpResponse($data, $status, $exception = null)
	{
	    
	    $error = $this->getRequest()->getHeader(
	            self::HEADER_ERRORS, 
	            self::HEADER_ERRORS_DEFAULT);
	    
	    $forceHtmlContentType = $this->getRequest()->getHeader(
	            self::HEADER_FORCE_CONTENT_HTML,
	            false);
	    
	    if ($error instanceof HeaderInterface) {
	        $error = $error->getFieldValue();
	    }
	    
	    $response = $this->getResponse();
	    
	    $headers = array(
	    	'Cache-Control' => 'no-cache, must-revalidate',
	        'Pragma' 		=> 'no-cache',
	    	'Expires' 		=> '2000-01-01 00:00:00',
            'Content-Type'  => 'application/json',
	    );
	    
	    if ($forceHtmlContentType) {
	        $headers['Content-Type'] = 'text/html';
	    }

	    $response->getHeaders()->addHeaders($headers);
	    
	    // update response status code
	    $response->setStatusCode(
        	$status
        );
	    
	    // update reason phrase
	    if($exception){
	        
	        if ($exception instanceof ServiceException) {
	            $message = $exception->getMessage();
	        } else {
	            $message = 'Unknown exception';
	        }
	        
	    	$response->setReasonPhrase(
    	        $message
	    	);
	    }
	    
	    if ($data instanceof \Zend\Http\Response) {
	        
    	    // Attach custom stream response sender listener
	        // to send the stream to output buffer in chunks
	        if ($data instanceof Stream) {
	            $sendReponseListener = $this->getServiceLocator()->get('SendResponseListener');
	            $sendReponseListener->getEventManager()->attach(
	                    SendResponseEvent::EVENT_SEND_RESPONSE,
	                    new StreamResponseSender(),
	                    10000);
	        }
	        
	        return $data;
	    } else {
	        
	        $responseModel = array(
                'd' => $data
	        );
	        
	        // Append exception data
	        if ($exception) {
	            
	            if ($error == self::HEADER_ERRORS_VERBOSE && $exception instanceof ServiceException) {
	                $responseModel['e'] = array(
                        'm' => $exception->getRawMessage(),
                        'c' => $exception->getCode(),
                        'a' => $exception->getVars()
	                );
	                
	            } else {
	                $responseModel['e'] = array(
                        'm' => $response->getReasonPhrase(),
                        'c' => $exception->getCode(),
	                );
	            }
	        }
	        
	        try {
	            $response->setContent(JsonEncoder::encode($responseModel, true));
	        } catch (Exception $e) {
	            
	            if ($e instanceof RecursionException) {
	                $message = self::CYCLIC_DATA_ERROR;
	            } else {
	                $message = $e->getMessage();
	            }
	            
	            $response->setReasonPhrase(
                    $message
	            );
	            
	            $response->setStatusCode(
                    self::STATUS_UNKNOWN_EXCEPTION
	            );
	            
	            $response->setContent(JsonEncoder::encode([
                    'd' => null,
                    'e' => [
	                   'm' => $message,
	                   'c' => $e->getCode()
	               ]
	            ], true));
	        }
	        
	        return $response;
	    }
	}
615443
public function jsonResponseSuccess(array $data = [], $status = 200, $code = 'success', array $headers = [], $options = 0)
    {
        return $this->jsonResponse()->success($data, $status, $code, $headers, $options);
    }
74805
public function json( $data = [], $status = 200, array $headers = [], $options = 0 )
	{
		if ( $data instanceof Arrayable && !$data instanceof JsonSerializable )
			$data = $data->toArray();

		return new JsonResponse( $data, $status, $headers, $options );
	}