{"record":{"id":"bab03d5906d22dcd","repo":"getgrav/grav","slug":"json-last-error-msg","errorCode":null,"errorMessage":"json_last_error_msg()","messagePattern":"json_last_error_msg\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"system/src/Grav/Framework/Psr7/Response.php","lineNumber":63,"sourceCode":"     *\n     * Note: This method is not part of the PSR-7 standard.\n     *\n     * This method prepares the response object to return an HTTP Json\n     * response to the client.\n     *\n     * @param  mixed  $data   The data\n     * @param  int|null $status The HTTP status code.\n     * @param  int    $options Json encoding options\n     * @param  int    $depth Json encoding max depth\n     * @return static\n     * @phpstan-param positive-int $depth\n     */\n    public function withJson(mixed $data, ?int $status = null, int $options = 0, int $depth = 512): ResponseInterface\n    {\n        $json = (string) json_encode($data, $options, $depth);\n\n        if (json_last_error() !== JSON_ERROR_NONE) {\n            throw new RuntimeException(json_last_error_msg(), json_last_error());\n        }\n\n        $response = $this->getResponse()\n            ->withHeader('Content-Type', 'application/json;charset=utf-8')\n            ->withBody(new Stream($json));\n\n        if ($status !== null) {\n            $response = $response->withStatus($status);\n        }\n\n        $new = clone $this;\n        $new->message = $response;\n\n        return $new;\n    }\n\n    /**\n     * Redirect.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/getgrav/grav/blob/6040efed04efa69b8209448ed81308e7c24147c2/system/src/Grav/Framework/Psr7/Response.php#L45-L81","documentation":"Error \"json_last_error_msg()\" thrown in getgrav/grav.","triggerScenarios":"Thrown at system/src/Grav/Framework/Psr7/Response.php:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"6040efed04efa69b8209448ed81308e7c24147c2","analyzedAt":"2026-08-17T05:07:31.593Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}