Surprisingly, validate_json function is returning false at an empty json object;
$empty_json_obj = "{}";
if(validate_json($empty_json_obj)) {
print_r("VALID");
}
else {
print_r("NOT VALID");
}
Output NOT VALID
validate_json function
function validate_json($data) {
if ( ! $data) {
return FALSE;
}
$result = (array) json_decode($data);
if ( ! is_array($result) || count($result) < 1) {
return FALSE;
}
return TRUE;
}
How to get this right, so that validate_json identify correctly empty json passed as json
count($results) < 1that gives you false on a empty json object...