Simple lua function to catch a nil when checking json values

Simple lua function to catch a nil when checking json values

function IsInString(theString, theText)
    print("IsInString (theString: '" .. theString .. "', theText: '" .. theText .. "').");
    if (tonumber(string.find(theString, theText)) == nil) then
        print(" String Not Found.");
        return false;
    else
        -- check the pos if the string to confirm (not nil is not enough)
        if (tonumber(string.find(theString, theText)) > 1) then
            print(" String Found.");
            return true;
        else
            print(" String Not Found.");
            return false;
        end
    end
end

I was doing this when processing json data but kept getting nil in the second elseif (nil was not being caught higher up.

if (event.response == nil) then
            --code
        elseif (event.response == "") then
            -- code
 
        elseif (tonumber(string.find(event.response, "ok")) > 1) then
            if (string.find(event.response, "true") > 1) then
                -- code
 
            end
            ...