Trying to understand table getdelegate() method

I am receiving json encoded data from a web service. However some of the data fields in the json encoded table are not always included. So after I “http.jsondecode( — web service response —)” I receive my data table, which I then wanted to check if a particular data field exists using the table.getdelegate() method.

So tried this and was expecting to receive a null response if the data field is not present, but I got this error message instead “Internal Server Error: the index ‘###’ does not exist”.

I was using the following code to check if it was present:
if (myDataTable.getdelegate(newDataField)) { // exists so can do something with the newDataField } else { // the newDataField does not exist }

I suspect I am doing something silly.

There is actually a much simpler way to do this, using the in keyword, which determins whether or not an index is in a table:

`local test = {
foo = “bar”,
abc = 123
};

// check if test has a field called "foo"
local foo = null;
if (“foo” in test) {
foo = test.foo;
} else {
server.log(“Could not find ‘foo’ in test”);
}`

Brilliant! Thanks.