Table
table.encode
Shared
Encodes a table into string
Syntax
local result = table.encode(input, mode = "JSON")Parameters
| Type | Name | Description |
|---|---|---|
table | input | Table to be encoded |
string | mode | Encoding mode: • "JSON" - JavaScript Object Notation• "YAML" - YAML Ain't Markup Language |
Returns
| Type | Name | Description |
|---|---|---|
string / bool | result | Encoded string on successful execution, or false on failure |
Examples
--Encode simple table to JSON
local data = {name = "John", age = 25}
local json = table.encode(data, "JSON")
engine.print(json) --{"name":"John","age":25}--Encode array to JSON
local colors = {"red", "green", "blue"}
local json = table.encode(colors, "JSON")
engine.print(json) --["red","green","blue"]--Encode numbers to JSON
local coords = {100, 200, 300}
local json = table.encode(coords, "JSON")
engine.print(json) --[100,200,300]--Encode boolean values to JSON
local settings = {enabled = true, debug = false}
local json = table.encode(settings, "JSON")
engine.print(json) --{"enabled":true,"debug":false}