Seldaek/monolog · error · RuntimeException
JSON encoding failed: {}. Encoding: {}
Error message
JSON encoding failed: {}. Encoding: {} What it means
Error "JSON encoding failed: {}. Encoding: {}" thrown in Seldaek/monolog.
Source
Thrown at src/Monolog/Utils.php:160
/**
* Throws an exception according to a given code with a customized message
*
* @param int $code return code of json_last_error function
* @param mixed $data data that was meant to be encoded
* @throws \RuntimeException
*/
private static function throwEncodeError(int $code, $data): never
{
$msg = match ($code) {
JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch',
JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded',
default => 'Unknown error',
};
throw new \RuntimeException('JSON encoding failed: '.$msg.'. Encoding: '.var_export($data, true));
}
/**
* Detect invalid UTF-8 string characters and convert to valid UTF-8.
*
* Valid UTF-8 input will be left unmodified, but strings containing
* invalid UTF-8 codepoints will be reencoded as UTF-8 with an assumed
* original encoding of ISO-8859-15. This conversion may result in
* incorrect output if the actual encoding was not ISO-8859-15, but it
* will be clean UTF-8 output and will not rely on expensive and fragile
* detection algorithms.
*
* Function converts the input in place in the passed variable so that it
* can be used as a callback for array_walk_recursive.
*
* @param mixed $data Input to check and convert if needed, passed by ref
*/
private static function detectAndCleanUtf8(&$data): voidView on GitHub (pinned to 57eb102834)
When it happens
Trigger: Thrown at src/Monolog/Utils.php:160 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Seldaek/monolog@57eb102834 (2026-08-17).
Data as JSON: /api/errors/6270fb322c17d982.
Report an issue: GitHub.