Available since Version 1.1.
Encodes a Lua value as a JSON string. Tables with sequential integer keys starting at 1 are encoded as JSON arrays; all other tables are encoded as JSON objects.
Syntax
JSON.Encode( value )Arguments
- value (any): The value to encode. Supported types are
table,boolean,number,string, andnil.
Return Values
- (string): A JSON string representation of the value.
Examples
local json = JSON.Encode({ name = "Homer", level = 1 })
print(json) -- Outputs: {"name":"Homer","level":1}local json = JSON.Encode({ "a", "b", "c" })
print(json) -- Outputs: ["a","b","c"]