Table index is nil

Hey everyone,

I’m running into an issue that I just can’t figure out. I have a JSON table set up as follows;

[ {    "Zipcode": 705,    "City": "AIBONITO",    "State": "PR"  },  {    "Zipcode": 36860,    "City": "HURTSBORO",    "State": "AL"  },  {    "Zipcode": 91406,    "City": "VAN NUYS",    "State": "CA"  },]

the code to access it is;

local fd = io.open(system.pathForFile("ZIPDATABASE.json")) local data = fd:read('\*a') fd:close() data = json.decode(data) local dbtbl = {} local record for i=1, #data do record = data[i] dbtbl[record["Zipcode"]] = { city = record.City, state = record.State } end

My problem is I keep getting “Table index is nil” as an error. I’m using this method for another database and it works fine. Not really sure whats happening. This is a very large JSON database as it has zip codes for every state in the USA. Would that be contributing to it?

Thanks! 

-B

doubt size is an issue

perhaps there are records in the database that are corrupt or incomplete

you could try to validate it and set a catch to “if #mydata==0” or something similar, before you try the import/convert.

So I figured it out. I was being really dumb. I searched for any null values there were 2 and now it works fine.

doubt size is an issue

perhaps there are records in the database that are corrupt or incomplete

you could try to validate it and set a catch to “if #mydata==0” or something similar, before you try the import/convert.

So I figured it out. I was being really dumb. I searched for any null values there were 2 and now it works fine.