php check if json is valid code example

Example 1: php check if json

function isJson($string) {
 json_decode($string);
 return (json_last_error() == JSON_ERROR_NONE);
}

Example 2: php check valid json string

@json_decode($page_str);
$json_OK=	json_last_error() == JSON_ERROR_NONE;

Example 3: php is json

function is_json($input_line) {
    if(is_string($input_line)){
        preg_match('/^\{(\s+|\n+)*(\"(.*)(\n+|\s+)*)*\}$|^\[(\s+|\n+)*\{(\s+|\n+)*(\"(.*)(\n+|\s+)*)*\}(\s+|\n)*\]$/', $input_line, $output_array);
        if (  isset($output_array) || !empty($output_array)) {
            return true;
        }
    }
    return false;
    }