hasError returns string error message if json is not valid or null otherwise.

@param $json
@return null|string
170494
private function hasError($json): ?string
    {
        if (!isset($json['table_name'])) {
            return "missing [table_name] property in JSON payload";
        }
        if (!isset($json['group_id'])) {
            return "missing [group_id] property in JSON payload";
        }
        if (!isset($json['criteria'])) {
            return "missing [criteria] property in JSON payload";
        }
        if (!isset($json['criteria']['version']) || $json['criteria']['version'] !== '1') {
            return "missing or invalid [criteria.version] property in JSON payload";
        }
        return null;
    }
79746
private static function extractErrorDescription($exception)
    {
        $json = Client::responseToArray(
            $exception->getResponse()
        );
        if (isset($json['error_description'])) {
            return $json['error_description'];
        } elseif (isset($json['message'])) {
            return $json['message'];
        } else {
            return null;
        }
    }
858544
public static function isJSON($json)
    {
        if ($json === '[]' || $json === '{}') {
            return true;
        } else if (is_array($json)) {
            return false;
        }

        return static::decode($json) != null;
    }
233358
private function getJsonErrorName($error)
    {
        $matches = array_keys(get_defined_constants(), $error, true);
        $prefix = 'JSON_ERROR_';
        $prefixLength = strlen($prefix);
        $name = 'UNKNOWN_ERROR';

        foreach ($matches as $match) {
            if (is_string($match) && strncmp($match, $prefix, $prefixLength) === 0) {
                $name = $match;
                break;
            }
        }

        return $name;
    }
211040
public static function getJSONErrorAsString()
	{
		switch(json_last_error())
		{
			case JSON_ERROR_NONE:
				$error =  NULL;
			break;
			
			case JSON_ERROR_DEPTH:
				$error = 'The maximum stack depth has been exceeded.';
			break;
				
			case JSON_ERROR_STATE_MISMATCH:
				$error = 'Invalid or malformed JSON.';
			break;

			case JSON_ERROR_CTRL_CHAR:
				$error = 'Control character error, possibly incorrectly encoded.';
			break;

			case JSON_ERROR_SYNTAX:
				$error = 'Syntax error, malformed JSON.';
			break;

			// PHP >= 5.3.3
			case JSON_ERROR_UTF8:
				$error = 'Malformed UTF-8 characters, possibly incorrectly encoded.';
			break;

			// PHP >= 5.5.0
			case JSON_ERROR_RECURSION:
				$error = 'One or more recursive references in the value to be encoded.';
			break;

			// PHP >= 5.5.0
			case JSON_ERROR_INF_OR_NAN:
				$error = 'One or more NAN or INF values in the value to be encoded.';
			break;

			case JSON_ERROR_UNSUPPORTED_TYPE:
				$error = 'A value of a type that cannot be encoded was given.';
			break;

			default:
				$error = NULL;
			break;
		}
		
		return $error;
	}
693674
protected function jsonErrorMessage($errorNumber)
    {
        $messages = array(
            JSON_ERROR_NONE => 'No error has occured',
            JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
            JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
            JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
            JSON_ERROR_SYNTAX => 'Syntax error',
            JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
        );
        return isset($messages[$errorNumber]) ? $messages[$errorNumber] : 'Unknown JSON encoding error';
    }
884986
private function parseJson($json)
    {
        $jsonPayload = json_decode($json, true);

        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new ParserException('Error parsing JSON: '
                . json_last_error_msg());
        }

        return $jsonPayload;
    }
510302
protected function fetchJsonError($json) {
		if (!$json->ok) {
			if (isset($this->errorMessages[$json->error])) {
				$errorMessage = $this->errorMessages[$json->error];
			} else {
				$errorMessage = 'Unknown error';
			}
			return array(
				'code' => $json->error,
				'message' => $errorMessage,
			);
		}
		else {
			return null;
		}
	}
221763
public static function isJson($string){

        if(!is_string($string)) return false;

        if(empty($string)) return false;

        json_decode($string);
        return (json_last_error() == JSON_ERROR_NONE);
    }
1311952
private static function getLastJsonError()
    {
        if (function_exists('json_last_error_msg')) {
            return json_last_error_msg();
        }
        static $errors = array(
            JSON_ERROR_NONE           => null,
            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_SYNTAX         => 'Syntax error, malformed JSON',
            JSON_ERROR_UTF8           => 'Malformed UTF-8 characters, possibly incorrectly encoded',
        );
        $error = json_last_error();

        return array_key_exists($error, $errors)
            ? $errors[$error]
            : sprintf('Unknown error (%s)', $error);
    }
117944
public function decode($json)
    {
        $data = json_decode($json, true);
        if ($data === null && json_last_error() != JSON_ERROR_NONE) {
            throw new JsonSerializerException('Invalid JSON to unserialize.');
        }

        if (!is_array($data)) {
            throw new JsonSerializerException('Given JSON cannot represent an object.');
        }

        if (mb_strpos($json, $this->encodingAnnotation) !== false) {
            $data = $this->decodeNonUtf8FromUtf8($data);
        }

        return $data;
    }
12021
public static function json2arr($json)
    {
        $result = json_decode($json, true);
        if (empty($result)) {
            throw new InvalidResponseException('invalid response.', '0');
        }
        if (!empty($result['errcode'])) {
            throw new InvalidResponseException($result['errmsg'], $result['errcode'], $result);
        }
        return $result;
    }
250796
private function isValidJsonStructure(string $json): bool
    {
        if ('{' === $json[0] && $json[strlen($json) - 1] !== '}') {
            return false;
        } elseif ('[' === $json[0] && $json[strlen($json) - 1] !== ']') {
            return false;
        } elseif ('{' !== $json[0] && '[' !== $json[0]) {
            return false;
        }

        return true;
    }
1261847
public static function jsonToArray($json)
    {
        if (empty($json)) {
            return null;
        }

        $array = json_decode($json, true);

        switch (json_last_error()) {
            case JSON_ERROR_NONE:
                $message = null;
                break;

            case JSON_ERROR_STATE_MISMATCH:
                $message = 'Invalid or malformed JSON';
                break;

            case JSON_ERROR_UTF8:
                $message = 'Malformed UTF-8 characters, possibly incorrectly encoded';
                break;

            case JSON_ERROR_DEPTH:
                $message = 'The maximum stack depth has been exceeded';
                break;

            case JSON_ERROR_CTRL_CHAR:
                $message = 'Control character error, possibly incorrectly encoded';
                break;

            case JSON_ERROR_SYNTAX:
                $message = 'Syntax error, malformed JSON';
                break;

            default:
                $message = 'Unknown error';
                break;
        }

        if (!empty($message)) {
            throw new \InvalidArgumentException('JSON Error: ' . $message);
        }

        return $array;
    }
766821
public static function checkLastError()
    {
        $error = json_last_error();

        if ($error == JSON_ERROR_NONE) {
            return;
        }

        $message = json_last_error_msg();

        throw new JsonException("JSON Error: " . $message, $error);
    }
899779
public static function hasError() {
		$error        = json_last_error();
		$errorMessage = array_key_exists($error, self::$errors) ? self::$errors[$error] : "Unknown error ({$error})";
		return $errorMessage;
	}
935211
protected function checkItAlreadyExists($json): bool
    {
        $pathName = $this->tableObject->getPathName();
        foreach (Arr::get($json, 'items', []) as $item) {
            if (Arr::get($item, 'url', '') == '/'.$pathName) {
                return true;
            }
        }

        return false;
    }