JSON
These are the methods available for JSON handling. They are available through the cloud.encode and cloud.decode namespaces.
You can also access the raw JSON module using: cloud.json
Decode
.decode.json
Converts a JSON string to a Lua table.
Signature
cloud.decode.json( json_string )
Parameters
Name | Description | Default | Required |
---|---|---|---|
json_string | A JSON decodable string. | none | Y |
Example
local result = cloud.decode.json('{"directive":"Table Me"}') -- result = { directive = "Table Me" }
Encode
.encode.json
Converts a Lua table to a JSON string.
Signature
cloud.encode.json( lua_table )
Parameters
Name | Description | Default | Required |
---|---|---|---|
lua_table | A JSON encodable Lua table | none | Y |
Returns
-
Success:
true
,result
-
Fail:
nil
,error
Usage
local result = cloud.encode.json({directive = "JSON Me"}) -- result = {"directive":"JSON Me"}
JTable
cloud.jtbl
A table extended with a :toJson
method, which returns a JSON encoding of the table data, if possible.
Signature
cloud.jtbl()
Parameters
none
Usage
local tbl = cloud.jtbl() tbl.username = "Jim" local json = tbl:toJson() -- `json` contains '{"username":"Jim"}'