Return a new JSON response from the application.

@param string|array $data
@param int          $status
@param array        $headers

@return \Symfony\Component\HttpFoundation\Response
@static
483756
public function error($data = [], $status = Response::HTTP_BAD_REQUEST, $headers = [])
    {
        return $this->response($data, $status, $headers);
    }
207121
public function json(array $data, $status = 200, $encodingOptions = 0)
    {
        return $this->response->withJson($data, $status, $encodingOptions);
    }
532440
public function respond($input, $status = self::INTERNAL_ERROR, array $header = [])
    {
        return ResponseHelper::fill($this->response, $input, $status, $header);
    }
1279172
public function outputJson($data = null, $status = 200)
    {
        $this->getContext()->getOutput()->outputJson($data, $status);
    }
508979
protected function seeSuccessResponse($data = null, $status = 200):JsonResponse
    {
        $response = app(Responder::class)->success($data, $status);

        $this->seeStatusCode($response->getStatusCode())->seeJson([
            'success' => true,
            'status' => $response->getStatusCode()
        ])->seeJsonStructure(['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;
  }
792069
public function json($data, $status = HttpMessage::HTTP_OK, $encodingOptions = 0)
    {
        $json = json_encode($data, $encodingOptions);
        $this->withStatusCode($status)
            ->withHeader('content-type', 'application/json')
            ->getBody()->write($json);
        return $this;
    }
382891
public static function json($data = array(), $status = 200, array $headers = array())
	{
		if ($data instanceof ArrayableInterface)
		{
			$data = $data->toArray();
		}

		return new JsonResponse($data, $status, $headers);
	}
797226
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0)
    {
        return $this->json($data, $status, $headers, $options)->setCallback($callback);
    }
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;
	    }
	}
826258
public function json($data, $status = 200)
    {
        $this->header('Content-Type: application/json');

        $this->statusCode($status);

        return json_encode($data);
    }
534281
public function withJson($data, $status = null, $encodingOptions = JSON_ENCODE_OPTION)
    {
        return parent::withJson($data, $status, $encodingOptions);
    }
340609
public function refresh($status = 302, $headers = [])
    {
        return $this->to($this->generator->getRequest()->path(), $status, $headers);
    }
240304
public function json($data = [], $status = 200, array $headers = [], $options = 0)
    {
        return new JsonResponse($data, $status, $headers, $options);
    }
945674
public function toRestResponse(int$status = 200, array $headers = []): RestResponseContract
	{
		return (new Response())->setData($this->toArray())->setStatus($status)->setHeaders($headers);
	}
234118
public function resourceJson($data = array(), $status = 200, array $headers = array())
  {
    $headers = array_merge($headers, $this->getRequestLimitHeader());
    $headers = array_merge($headers, $this->getConfig('headers'));

    return $this->getResponse()->resourceJson($data, $status, $headers);
  }
871333
protected function seeSuccess($data = null, $status = 200)
    {
        $response = $this->seeSuccessResponse($data, $status);
        $this->seeSuccessData($response->getData(true)['data']);

        return $this;
    }