For decoding json-files with lua, I found https://somedudesays.com/2019/12/using-json-with-lua/
However when trying to adapt the examples for my use, got stuck.
Installation of Luarocks and lunajson as instructed, without any problem.
Text at url claims tested with lua incl. lua 5.3
Looked very simple, but apparently something missing/wrong in the examples.
Original example line 002 gave error report :
Code: Select all
module 'lunajson' not found
Checking in the folders /usr/local/share/lua/5.x/ nowhere found module lunajson.
Next error report is related to line 008:
Code: Select all
syntax error near 'local'
Or an equivalent, 'short' method to extract info from a json-file?
Code: Select all
commandArray = {}
-- Other scriptlines
-- Lines 001 ~ 005 = Example using luarocks/lunajson for json-readout
-- lunajson = require 'lunajson'
-- local jsonraw = '{"test":[1,2,3,4]}'
-- local jsonparse = lunajson.decode( jsonraw )
-- print( jsonparse["test"][ 1 ] .. ", " .. jsonparse["test"][ 2 ] .. ", " .. jsonparse["test"][ 3 ] .. ", " .. jsonparse["test"][ 4 ] )
-- Lines 006 ~ 012 = Testing, read remote device & decode contents of json-file [for switch]
local lunajson = require lunajson
local jsonraw = 'http://192.168.0.185/json.htm?type=devices&rid=337'
local jsonparse = lunajson.decode( jsonraw )
print( jsonparse )
print( jsonparse["Sunrise"] )
print( jsonparse["result"][0][Data] )
-- Other scriptlines
return commandArray