특정 문자열의 JOSN 형식 여부 검사

 

<?php

    function isJson(string $string):bool
    {
        $rtnValue   =   FALSE;
       
        json_decode($string);
        
        if( json_last_error() == JSON_ERROR_NONE )
        {
            $rtnValue   =   true;
        }//    end if
        
        return $rtnValue;
    }// end function

?>

 

참고자료 : https://www.php.net/manual/en/function.json-last-error