Help with save/load table using JSON

I figured out how to save tables ( and load ) but how do I check for specific setting in saved table if it is a dynamic variable?

For example when I save I get this in my .json table:

{ " variable1":“20” , “variable2”:“30” }

Meaning I have this in my code:

variable1 = 20

variable2 = 30

Now how can I check how many variables do I have if I plan to have up to 20 of them?

I tried something like this:

for i=1 , 20 do

      if ( myTable.variable … i   ~=   nil ) then

            howManyVariables = howManyVariables + 1

      else

            i = 20

end

Not sure what you’re trying to do exactly but I think you’d want this:

myTable["variable"..i]

So you are saying that

myTable[“variable”…i]

is the same as ( presuming i is 2)

myTable.variable.2

Close but not quite.  @hasty meant this:

local i = 2 myTable["variable" .. i] -- same as: myTable["variable2"] -- same as: myTable.variable2

I get it now, thanks :slight_smile:

Not sure what you’re trying to do exactly but I think you’d want this:

myTable["variable"..i]

So you are saying that

myTable[“variable”…i]

is the same as ( presuming i is 2)

myTable.variable.2

Close but not quite.  @hasty meant this:

local i = 2 myTable["variable" .. i] -- same as: myTable["variable2"] -- same as: myTable.variable2

I get it now, thanks :slight_smile: