Как проверить JSON в PHP

Вариант 1.

<?php
function isJSON($string) {
    if(is_array($string)) return false;
    if(!empty($string)){
        if($string == '{}') return true;
        json_decode($string);
        if(json_last_error() === JSON_ERROR_NONE) return true;
    }
    return false;
}

$json = '{"website":{"domain":"wtools.io","title":"Online Web Tools"}}';
if(isJSON($json)){
    echo "Valid JSON string";
} else {
    echo "Not valid JSON string";
}

Вариант 2.

<?php
function isJSON($string) {
    if(!empty($string) && !is_array($string)){
        if($string == '{}') return [];
        $res = json_decode($string, true);
        if(json_last_error() === JSON_ERROR_NONE) return $res;
    }
    return false;
}

$json = '{"website":{"domain":"wtools.io","title":"Online Web Tools"}}';
$data = isJSON($json);
if($data!==false){
    print_r($data);
} else {
    echo "Not valid JSON string";
}
Валидаторы PHPJSON