add data to table
Posted: Saturday 19 October 2019 14:55
Hi,
Somebody knows how to add data/record to:
local testdata ='{"veld1": "waarde 1","veld2": "waarde 2"}'
for example by:
testdata.add("veld3": "waarde 3")
Somebody knows how to add data/record to:
local testdata ='{"veld1": "waarde 1","veld2": "waarde 2"}'
for example by:
testdata.add("veld3": "waarde 3")
Code: Select all
return {
active = true,
on = {
devices = {'test'}
},
data = {
switchevents = { initial = {} }
},
execute = function(dz, item, info)
local testdata ='{"veld1": "waarde 1","veld2": "waarde 2"}'
function deepdump( tbl )
local checklist = {}
local function innerdump( tbl, indent )
checklist[ tostring(tbl) ] = true
for k,v in pairs(tbl) do
print (indent .. tostring(k) .. " ===> value: ".. tostring(v) )
if (type(v) == "table" and not checklist[ tostring(v) ]) then
innerdump(v,indent .. tostring(k) .. ".")
end
end
end
checklist[ tostring(tbl) ] = true
innerdump( tbl, "Key: " )
end
-- how to add "veld3": "waarde 3" to testdata
testdata.add("veld3": "waarde 3")
local myTable = dz.utils.fromJSON(testdata)
deepdump(myTable) -- use this function call to see the structure of your table
end
}