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
local data = {name = "John", age = 25}
local json = table.encode(data, "JSON")
engine.print("info", json) --'{"name":"John","age":25}'local colors = {"red", "green", "blue"}
local json = table.encode(colors, "JSON")
engine.print("info", json) --'["red","green","blue"]'local coords = {100, 200, 300}
local json = table.encode(coords, "JSON")
engine.print("info", json) --'[100,200,300]'local settings = {enabled = true, debug = false}
local json = table.encode(settings, "JSON")
engine.print("info", json) --'{"enabled":true,"debug":false}'