Library of Functions


Description


Converts a Lua table into a serialised JSON string.
 
Scope
This function is only defined in the scope of a virtual device.  It will not work in a scene.

Usage and Arguments


json.encode(lua_table)

  • lua_table (table): a Lua table to be serialised into a JSON string.

Returned Values


string: The encoded JSON string representing the original Lua table.

Examples


jsonTable = { value1 = 512, value2 = json.null }
jsonString = json.encode(jsonTable)
 
-- after encoding jsonString variable contains '{ "value2": null, "value1": 512 }' string
fibaro:debug(jsonString)
 
-- null will be decoded to json.null value
jsonTable = json.decode(jsonString)
if(jsonTable.value2 == json.null)
then
  fibaro:debug('null value successfully decoded')
end

See Also


json.decode
json.null