I think you are doing something incorrect when encoding.
Using strings as numerical keys is messy and is only going to make your work worse as you continue to use them. Using integers or actual array objects is saving you a lot of hassle later.
Playing with encoding and decoding I see no issues with []
Here is a quick test code for processing the json file with it re-encoding and printing to verify the file is ok, as well as how to go about inserting new elements.
local function test()
local vars = {}
local path = system.pathForFile("test.json", system.ResourceDirectory)
local file = io.open(path, "r")
if file then
local fileStr = file:read("\*a")
file:close()
print("Json", fileStr)
if fileStr then
vars = require("json").decode(fileStr) or {}
end
--alternatively you could do 'for i = 1, #vars.myTable do local val = vars.myTable[i] for iterating
for idx, val in ipairs(vars.myTable) do
print(val.min, val.value, val.hour, val.day)
end
table.insert(vars.myTable, {min = 0, value = "Some String", hour = 24, day = 7})
print(require("json").encode(vars))
end
end
And using the same json file (called test.json in here) with [] there are no issues. It also adds the benefit that they are guaranteed first to last ordered (and therefore reorderable on LUA or Json sides and both will maintain that order), and you don’t lose your # operator functionality as you do with string-based numerical keys. [import]uid: 134101 topic_id: 32737 reply_id: 130165[/import]