encode and print the result to json (used for ajax routines)
@param  string $status  status
@param  string $message message
@param  mixed $data    data
@param bool $return should return json
@return string          json encoded string
432103
public static function print_status($status = 200, $data = [], $options = JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK, $return = false) {
        if (is_numeric($status)) $status_code = $status;
        else if (is_bool($status)) $status_code = $status ? 200 : 400;
        else $status_code = strtolower($status) === 'ok' ? 200 : 400;

        $status_name = self::http_code($status_code);
        self::set_status($status_code);

        if (!is_array($data) && !$data) {
            $data = ['message' => $status_name];
        } else if (is_string($data)) {
            $data = ['message' => $data];
        }

        if ($status_code >= 400 || $status_code < 200) $data['error'] = $status_name;

        $json = json_encode($data, $options);
        if ($return) return $json;
        else echo $json;
    }
992117
public function json($data = [], $status = 200, array $headers = [], $options = false)
    {
        $options = ($options === false) ? JSON_PRETTY_PRINT : $options;

        return new JsonResponse($data, $status, $headers, $options);
    }
1169156
public function jsonSuccess($data = null, $message = null) {
        if (!is_array($message)) {
            $message = ['messages' => $message];
        }
        if ($data instanceof ArrayAble) {
            $data = $data->toArray();
        }
        return $this->json(array_merge(array(
            'code' => 200,
            'status' => __('success'),
            'data' => $data
        ), $message));
    }
670841
public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
    {
        if ($exception = config("responder.exceptions.$errorCode")) {
            if (class_exists($exception)) {
                throw new $exception();
            }
        }

        return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
    }
1374391
public function response($data = [], $status = Response::HTTP_OK, $headers = [])
    {
        return new JsonResponse($data, $status, $headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
1364041
private function error(string $message, $status = 1)
    {
        $this->printer->printError($message);
        exit($status);
    }
1014723
public function success($data = [], $status = Response::HTTP_OK, $headers = [])
    {
        return $this->response($data, $status, $headers);
    }
97327
final public static function print_json(
		int $errno=0, $data=null, int $http_code=200, int $cache=0
	) {
		$json = json_encode(compact('errno', 'data'));
		self::start_header($http_code, $cache, [
			'Content-Length: ' . strlen($json),
			'Content-Type: application/json',
		]);
		static::halt($json);
	}
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);
    }
684602
public static function respond($status = 404, $message = '') {
        http_response_code($status);
        if (Request::isAjaxRequest()) {
            @header('ajax: 1');
            Response::getInstance()->output(['message' => $message ? $message : __('error occurred')]);
            Response::getInstance()->close();
        } else {
            if ($status == 404) {
                $data ['message'] = $message;
                $view             = template('404.tpl', $data);
            } else if ($status == 403) {
                $data ['message'] = $message;
                $view             = template('403.tpl', $data);
            } else if ($status == 500) {
                $data ['message'] = $message;
                $view             = template('500.tpl', $data);
            } else if ($status == 503) {
                $data ['message'] = $message;
                $view             = template('503.tpl', $data);
            } else if ($message) {
                if (is_array($message)) {
                    $view = new JsonView($message);
                } else {
                    $view = new SimpleView($message);
                }
            } else {
                $view = null;
            }
            if ($view) {
                Response::getInstance()->output($view);
                Response::getInstance()->close();
            }
        }
        exit (1);
    }
1257355
public function message($message, $success = 0, $return = false)
    {
        $array = array(
            'success' => $success,
            'message' => $message
        );

        $url = $this->saveURL . $this->saveName;

        // Cross-domain redirect to callback url
        if ($this->redirect)
        {
            $this->redirectURL .= '&success=' . $success . '&message=' . $message;

            if ($success == 1)
            {
                $this->redirectURL .= '&url=' . $url;
            }

            $this->redirect();
        }
        else
        {
            echo "success =>" . $success;
            if ($success == 1)
            {
                $array['url'] = $url;
            }

            $this->message = $array = json_encode($array);

            if ($return)
            {
                return $array;
            }
            else
            {
                echo $array;
            }
        }
    }
4788
protected function fail($message = null, $validation = null)
    {
        $this->trigger('json-fail', $this, $message, $validation);
        $this->trigger('response-fail', $this, $message, $validation);

        $json = array('error' => true);

        if($message) {
            $json['message'] = $message;
        }

        if($validation) {
            $json['validation'] = $validation;
        }

        $body = json_encode($json, JSON_PRETTY_PRINT);

        $this->response
            ->set('headers', 'Content-Type', 'text/json')
            ->set('body', $body);

        return $body;
    }
186622
public function validSuccessJsonResponse($message = 'Success', $data = [], $redirect = null)
    {
        return response()->json(
            [
                'code' => '200',
                'message' => $message,
                'data' => $data,
                'errors' => [],
                'redirect' => $redirect,
            ], 200, [], JSON_PRETTY_PRINT
        );
    }
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;
    }
566103
public function streamJson(array $data = [], $status = 200, array $config = []): SymfonyResponse
    {
        return Response::stream($this->createJsonResponse($data, $config), $status, [
            'Content-Type' => 'application/json',
        ]);
    }
111221
protected function successJson(array $data = null, OutputInterface $output)
    {
        $result = ['ok' => true];

        if (!empty($data) && is_array($data)) {
            $result = array_merge($result, $data);

            if (!$result['ok'] === true) {
                $result['ok'] = true;
            }
        }

        $output->writeln(json_encode($result));

        return 0;
    }
62276
public function aSuccess($message,$url='',$data=[])
    {
        $url=is_null($url) || $url=='' ? 'javascript:history.back(-1)' : $url;
        if(Request::isAjax() ){
            return $this->json(0,$message,array_merge($data,['url'=>url($url)]));
        }else{
            return $this->success($message,$url);
        }
    }