The Lua CJSON module provides JSON support for Lua.
Features
WebHMI supports this module starting from version WebHMI 3.4.
Documentation for CJSON module is available at official site.
There are 2 most important functions: cjson.encode and cjson.decode.
cjson.encode will serialise a Lua value into a string containing the JSON representation.
Example:
value = { true, { foo = "bar" } } json_text = cjson.encode(value) -- Returns: '[true,{"foo":"bar"}]'
cjson.decode will deserialise any UTF-8 JSON string into a Lua value or table.
Example:
json_text = '[ true, { "foo": "bar" } ]' value = cjson.decode(json_text) -- Returns: { true, { foo = "bar" } }
If your task is extract from the 7bit LoRA AirGate's JSON package then use to following code
local encoded = GetReg("encoded_json") local decoded_table = cjson.decode(encoded) for i, v in pairs(decoded_table) do TRACE(i .. " = " .. tostring(v)) -- show all the content of packet. end temp_int = decoded_table.temp_int -- example of extraction