WP_REST_Server::get_json_last_error()protectedWP 4.4.0

Returns if an error occurred during most recent JSON encode/decode.

Strings to be translated will be in format like "Encoding error: Maximum stack depth exceeded".

Method of the class: WP_REST_Server{}

No Hooks.


false|String. Boolean false or string error message.


// protected - for code of main (parent) or child class
$result = $this->get_json_last_error();


Since 4.4.0 Introduced.

WP_REST_Server::get_json_last_error() code WP 6.3

protected function get_json_last_error() {
	$last_error_code = json_last_error();

	if ( JSON_ERROR_NONE === $last_error_code || empty( $last_error_code ) ) {
		return false;

	return json_last_error_msg();