Check if a given string is valid JSON by attempting to decode it.
Source Code
$string = '{"name":"John","age":30}';
$isJson = json_decode($string, true) && (json_last_error() == JSON_ERROR_NONE);
echo $isJson ? "String is valid JSON" : "String is not valid JSON";