Table
table.decode
Shared
Decodes an encoded string into equivalent table
Syntax
local result = table.decode(input, mode = "JSON")Parameters
| Type | Name | Description |
|---|---|---|
string | input | Encoded string to be decoded |
string | mode | Decoding mode: • "JSON" - JavaScript Object Notation• "YAML" - YAML Ain't Markup Language |
Returns
| Type | Name | Description |
|---|---|---|
table / bool | result | Decoded table on successful execution, or false on failure |
Examples
local json = '{"name":"John","age":25}'
local data = table.decode(json)
engine.print("info", data.name) --'John'
engine.print("info", data.age) --25local json = '["red","green","blue"]'
local colors = table.decode(json)
engine.print("info", colors[1]) --'red'
engine.print("info", colors[2]) --'green'local json = '[100,200,300]'
local values = table.decode(json)
engine.print("info", values[1], values[2], values[3]) --100 200 300local json = '{"enabled":true,"debug":false}'
local settings = table.decode(json)
engine.print("info", settings.enabled) --true
engine.print("info", settings.debug) --false