Renders JSON response
Disables view

@param array|\Phalcon\Http\ResponseInterface $data
@return null|\Phalcon\Http\ResponseInterface
420306
protected function jsonResponse($data = array())
    {
        $this->view->disable();
        $this->response->setContentType('application/json', 'UTF-8');

        return $this->response->setJsonContent($data);
    }
725793
public function render($name, $data)
    {
        if (isset($data['value'])) {
            $value = $data['value'];
            unset($data['value']);
        } elseif (isset($data['name'])) {
            $value = $this->request->getInput($data['name'], '');
        } else {
            $value = null;
        }

        $method = '_render_' . $name;
        if (method_exists($this, $method)) {
            return $this->$method($data, $value);
        } else {
            throw new InvalidArgumentException(['`:type` type is not exist', 'type' => $name]);
        }
    }
367294
public function render($view, $data = [], $mergeData = [])
    {
        if ($this->request()->ajax() && $this->request()->wantsJson()) {
            return app()->call([$this, 'ajax']);
        }

        if ($action = $this->request()->get('action') and in_array($action, $this->actions)) {
            if ($action == 'print') {
                return app()->call([$this, 'printPreview']);
            }

            return app()->call([$this, $action]);
        }

        return view($view, $data, $mergeData)->with($this->dataTableVariable, $this->getHtmlBuilder());
    }
1017242
public function respondWithSuccess(array $data = []): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_OK)->respond([
            'status' => [
                'http_code' => $this->getStatusCode(),
            ],
            'data' => $data,
        ]);
    }
360816
public function seeJson(array $data = null, $negate = false)
    {
        if (is_null($data)) {
            $this->assertJson(
                $this->response->getContent(), "JSON was not returned from [{$this->currentUri}]."
            );

            return $this;
        }

        try {
            return $this->seeJsonEquals($data);
        } catch (ExpectationFailedException $e) {
            return $this->seeJsonContains($data, $negate);
        }
    }
514464
public static function clientException(ResponseInterface $response, $data)
    {
        return static::fromResponse(
            $response,
            isset($data['message']) ? $data['message'] : json_encode($data)
        );
    }
1330334
public function renderResponse(BlockInterface $block, array $parameters = array(), Response $response = null)
    {
        $view = $this->getView($block);

        if ($response) {
            $this->setResponseHeaders($block, $response);
        }

        return $this->blockRenderer->render($view, $parameters, $response);
    }
1245369
public function renderFromString(ResponseInterface $response, $templateString, array $data = array())
    {
        $this->view->loadString($templateString);
        $this->renderWithData($response, $data);
        return $response;
    }
546238
public function found(array $data): Response
    {
        $view = $data['view'] ?? '';
        $templateVars = $data['vars'] ?? [];
        $this->response->setBody(
            $this->renderer->render($view, $templateVars)
        );
        return $this->response;
    }
667773
protected function json($data) {
        $response = Router::getInstance()->response;
        $response->headers->set('Content-type', 'application/json');
        $response->setBody(to_json($data));
    }
157794
public function renderMessageBox($data=null)
    {
        $this->beforeRender($data);
        
        $this->beforeRenderView();
        
        // use view inner view/message.html
        $output = $this->getView()->renderMessageBox($this->responseData()->all());
        
        return $this->renderText($output);
    }
18643
final public function render($template=null, $data=null)
    {
        $renderType = $this->getRenderType();
        switch ($renderType) {
            case 'json':
                $this->renderJson($data);
                break;
            case 'xml':
                $this->renderXml($data);
                break;
            case 'html':
                $this->renderHtml($template, $data);
                break;
            default:
                $string = print_r($data, true);
                $this->renderText($string);
                break;
        }
        
        return $this->response;
    }
126856
public function render(ReportInterface $subject, Data $data)
    {
        if (null === $type = $subject->getRenderer()) {
            throw new \InvalidArgumentException('Cannot render data for ReportInterface instance without renderer defined.');
        }

        /** @var RendererInterface $renderer */
        $renderer = $this->registry->get($type);

        return $renderer->render($subject, $data);
    }
206643
public function renderPage($data, $status = 200)
    {
        // get view class
        $view = $this->di->get("view");
        // creates the views with viewify function
        array_key_exists("views", $data) && $this->viewify($data["views"]);

        $data["stylesheets"] = ["css/style.css"];
        $data["javascripts"] = ["js/index.js"];

        // Add layout, render it, add to response and send.
        $view->add("wrappedApp", $data, "wrappedApp");
        $body = $view->renderBuffered("wrappedApp");
        $this->di->get("response")->setBody($body)
                                  ->send($status);
        exit;
    }
370090
protected function _renderContent($data)
    {
        $options = $data['options'];

        if ($options instanceof Traversable) {
            $options = iterator_to_array($options);
        }

        if (!empty($data['empty'])) {
            $options = $this->_emptyValue($data['empty']) + (array)$options;
        }
        if (empty($options)) {
            return [];
        }

        $selected = isset($data['val']) ? $data['val'] : null;
        $disabled = null;
        if (isset($data['disabled']) && is_array($data['disabled'])) {
            $disabled = $data['disabled'];
        }
        $templateVars = $data['templateVars'];

        return $this->_renderOptions($options, $disabled, $selected, $templateVars, $data['escape']);
    }
1148598
public function renderFormAction(
        Action $action,
        Request $request,
        FormInterface $form,
        $data = null,
        array $viewParameters = []
    ): Response {
        $viewParameters = array_merge($this->getViewParameters($action, $request, $form, $data), $viewParameters);

        return $this->renderAction($action, $viewParameters);
    }
683532
protected function getResponseAsJson( ResponseInterface $response ) {
        if( $response->hasHeader('Content-Type') ) {
            $typeHeader = $response->getHeader('Content-Type');
            $contentType = array_shift($typeHeader);

            if( stripos( $contentType, 'application/json' ) === 0 ) {
                return json_decode($response->getBody(), false);
            }
        }

        return null;
    }