{"record":{"id":"6270fb322c17d982","repo":"Seldaek/monolog","slug":"json-encoding-failed-encoding","errorCode":null,"errorMessage":"JSON encoding failed: {}. Encoding: {}","messagePattern":"JSON encoding failed: (.+?)\\. Encoding: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Monolog/Utils.php","lineNumber":160,"sourceCode":"\n    /**\n     * Throws an exception according to a given code with a customized message\n     *\n     * @param  int               $code return code of json_last_error function\n     * @param  mixed             $data data that was meant to be encoded\n     * @throws \\RuntimeException\n     */\n    private static function throwEncodeError(int $code, $data): never\n    {\n        $msg = match ($code) {\n            JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',\n            JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',\n            JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',\n            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',\n            default => 'Unknown error',\n        };\n\n        throw new \\RuntimeException('JSON encoding failed: '.$msg.'. Encoding: '.var_export($data, true));\n    }\n\n    /**\n     * Detect invalid UTF-8 string characters and convert to valid UTF-8.\n     *\n     * Valid UTF-8 input will be left unmodified, but strings containing\n     * invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed\n     * original encoding of ISO-8859-15. This conversion may result in\n     * incorrect output if the actual encoding was not ISO-8859-15, but it\n     * will be clean UTF-8 output and will not rely on expensive and fragile\n     * detection algorithms.\n     *\n     * Function converts the input in place in the passed variable so that it\n     * can be used as a callback for array_walk_recursive.\n     *\n     * @param mixed $data Input to check and convert if needed, passed by ref\n     */\n    private static function detectAndCleanUtf8(&$data): void","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Seldaek/monolog/blob/57eb1028342134e701e77c617565d51b6e5a2a53/src/Monolog/Utils.php#L142-L178","documentation":"Error \"JSON encoding failed: {}. Encoding: {}\" thrown in Seldaek/monolog.","triggerScenarios":"Thrown at src/Monolog/Utils.php:160 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":"57eb1028342134e701e77c617565d51b6e5a2a53","analyzedAt":"2026-08-17T02:36:30.259Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}