I worked on it a little bit more and now I believe I just have a logic error now.
local path = system.pathForFile("SaveFile2.txt", system.DocumentsDirectory) json = require "json" function save(dataTable) file = io.open(path, "r+") if file then print("File Exists") contents = file:read() or "[]" newTable = json.decode(contents) print("File Contents:" .. contents) table.insert(newTable,dataTable) encodedJson = json.encode(newTable) file:write(encodedJson) else print("File does not exist") file = io.open(path, "w") a = {} table.insert(a,dataTable) file:write(json.encode(a)) print("Created new file \"SaveFile2.txt\" With source = " .. json.encode(a)) end file:close() end save({1,2,3})
now I ran this a few times and this is the output I got
22:11:53.293 File does not exist
22:11:53.303 Created new file “SaveFile2.txt” With source = [[1,2,3]]
22:12:12.569 File Exists
22:12:12.569 File Contents:[[1,2,3]]
22:12:16.626 File Exists
22:12:16.626 File Contents:[[1,2,3]][[1,2,3],[1,2,3]]
22:12:24.525 File Exists
22:12:24.525 File Contents:[[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]]
22:12:34.756 File Exists
22:12:34.756 File Contents:[[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]]
22:12:37.902 File Exists
22:12:37.902 File Contents:[[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]]
22:12:40.739 File Exists
22:12:40.739 File Contents:[[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]][[1,2,3],[1,2,3]]
the end result of me running this should have looked like this
[[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3],[1,2,3]]