21.11.2018, 11:28
Use this for JSON:
Code:
require('json')
file = '/home/ftp/data.json'
data = json.pdecode(io.readfile(file))
if type(data) == 'table' and type(data.objects) == 'table' then
for id, obj in pairs(data.objects) do
id = tonumber(obj.id or id)
if type(id) == 'number' and type(obj.name) == 'string' then
db:update('objects', { name = obj.name }, { id = id })
end
end
os.remove(file)
end