protected function jsonEncode(Field $f, $value)
    {
        // constant supported only starting PHP 7.3
        if (!defined('JSON_THROW_ON_ERROR')) {
            define('JSON_THROW_ON_ERROR', 0);
        }

        $res = json_encode($value, JSON_THROW_ON_ERROR, 512);
        if (JSON_THROW_ON_ERROR == 0 && json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception([
                'There was error while encoding JSON',
                'code'  => json_last_error(),
                'error' => json_last_error_msg(),
            ]);
        }

        return $res;
    }
protected function jsonEncode(Field $f, $value)
    {
        // constant supported only starting PHP 7.3
        if (!defined('JSON_THROW_ON_ERROR')) {
            define('JSON_THROW_ON_ERROR', 0);
        }

        $res = json_encode($value, JSON_THROW_ON_ERROR, 512);
        if (JSON_THROW_ON_ERROR == 0 && json_last_error() !== JSON_ERROR_NONE) {
            throw new Exception([
                'There was error while encoding JSON',
                'code'  => json_last_error(),
                'error' => json_last_error_msg(),
            ]);
        }

        return $res;
    }
protected function jsonEncode ( Field $ f , $ value ) { // constant supported only starting PHP 7.3 if ( ! defined ( 'JSON_THROW_ON_ERROR' ) ) { define ( 'JSON_THROW_ON_ERROR' , 0 ) ; } $ res = json_encode ( $ value , JSON_THROW_ON_ERROR , 512 ) ; if ( JSON_THROW_ON_ERROR == 0 && json_last_error ( ) !== JSON_ERROR_NONE ) { throw new Exception ( [ 'There was error while encoding JSON' , 'code' => json_last_error ( ) , 'error' => json_last_error_msg ( ) , ] ) ; } return $ res ; }
JSON encoding with proper error treatment.

@param Field $f
@param mixed $value

@return string
JSON encoding with proper error treatment .