Write a function to validate your json string like:
function jsonValidator($str=NULL) {
if (is_string($str)) {
@json_decode($str);
return (json_last_error() === JSON_ERROR_NONE);
}
return false;
}
In your code call this method to check either json is valid or not, it will return you boolean value.
$readJSONFile = file_get_contents($url);
if(jsonValidator($readJSONFile))
{
$table = json_decode($readJSONFile);
}