Converting Tables in a table to a json string

Hi all,

I’m trying to convert every table in a table to a JSON string. Without luck.

I have atm:

for _, table in pairs(localtable) do
  if istable(table) then
   localtable[table] = util.TableToJSON(localtable[table])

Why is it not working and what am I doing wrong?

Thanks, Darrell.

You’re setting the index of the table to the table itself; localtable[table] will ALWAYS be nil in that code. You need to set the index to the index of the original table and convert the value for that index to a JSON string.

for i, v in pairs(localtable) do
  if istable(v) then
   localtable* = util.TableToJSON(v)

[QUOTE=AK to Spray]


That makes sence, I was thinking that v would return the tablename, but because a loop works with keys and values that doesn’t work. Now it works, thank you!