Vital.sandbox
Table

table.decode

Shared

Decodes an encoded string into equivalent table


Syntax

local result = table.decode(input, mode = "JSON")

Parameters

TypeNameDescription
stringinputEncoded string to be decoded
stringmodeDecoding mode:
"JSON" - JavaScript Object Notation
"YAML" - YAML Ain't Markup Language

Returns

TypeNameDescription
table / boolresultDecoded table on successful execution, or false on failure

Examples

--Decode JSON object
local json = '{"name":"John","age":25}'
local data = table.decode(json)
engine.print(data.name) --John
engine.print(data.age) --25
--Decode JSON array
local json = '["red","green","blue"]'
local colors = table.decode(json)
engine.print(colors[1]) --red
engine.print(colors[2]) --green
--Decode JSON numbers
local json = '[100,200,300]'
local values = table.decode(json)
engine.print(values[1], values[2], values[3]) --100  200  300
--Decode JSON boolean values
local json = '{"enabled":true,"debug":false}'
local settings = table.decode(json)
engine.print(settings.enabled) --true
engine.print(settings.debug) --false

On this page