util.table.decode
Shared
Decodes a JSON string into an equivalent table
Syntax
local result = util.table.decode(input)Parameters
| Type | Name | Description |
|---|---|---|
string | input | JSON string to decode |
Returns
| Type | Name | Description |
|---|---|---|
table | bool | result | Decoded table on successful execution, false otherwise |
Examples
local json = '{"name":"John","age":25}'
local data = util.table.decode(json)
core.engine.print("info", data.name) -- 'John'
core.engine.print("info", data.age) -- 25local json = '["red","green","blue"]'
local colors = util.table.decode(json)
core.engine.print("info", colors[1]) -- 'red'
core.engine.print("info", colors[2]) -- 'green'local json = '[100,200,300]'
local values = util.table.decode(json)
core.engine.print("info", values[1], values[2], values[3]) -- 100 200 300local json = '{"enabled":true,"debug":false}'
local settings = util.table.decode(json)
core.engine.print("info", settings.enabled) -- true
core.engine.print("info", settings.debug) -- false