I want to store my or a group of my device_id's and a logical name in a table and store that table in a global var. That works fine via the API.
To retrieve the global var I use the Get request that gives me a response body in JSON. The values stored can be found in response.value which gives me these values: [DEBUG] 09:50:21: [{"id":"103","device":"Vloerlamp"},{"id":"215","device":"LampOpStatief"},{"id":"101","device":"TuinLinks"},{"id":"55","device":"TuinRechts"},{"id":"116","device":"Schuur"},{"id":"61","device":"Boedha"},{"id":"105","device":"Eiland"},{"id":"213","device":"Heklicht"},{"id":"48","device":"LedBoekenkast"},{"id":"154","device":"Yielde"},{"id":"177","device":"Kerstboom"},{"id":"178","device":"Kerstverlichting"},{"id":"194","device":"Buddha"},{"id":"217","device":"Leeslamp"}]
I would expect a table = json:decode(response.value); would give me the table I need to build a loop and do something with the devices like turnoff or turnon.
But I get this error on the decode:
[DEBUG] 10:14:05: 2019-08-11 10:14:05.372820 [ fatal] Unknown exception: /usr/share/lua/5.2/json/util.lua:55: bad argument #1 to 'pairs' (table expected, got string)
If I use the GetGlobal() statement and passes that reponse to the decode the it works without an issue and I can process the table.
I have read a lot of topics on this but until now I am still clueless. Any help appreciated.
I am also a bit confused with how LUA handles strings, tables and JSON.