I am unable to handle JSON decode errors. Here is my code:
try {
$jsonData = file_get_contents($filePath) . \']\';
json_decode returns null when a error occurs, like no valid json or exceeded depth size. So basically you just check with if whether the jsondata you obtained is null or not. If it is, use json_last_error to see what went wrong, if not then continue with the script.
$json_data = json_decode($source, true);
if($json_data == null){
echo json_last_error() . "
";
echo $source; // good to check what the source was, to see where it went wrong
}else{
//continue with script
}
Something like that should work.