json.encode(value)

Encode any Lua value in a JSON representation string, following those rules :

Lua value type JSON
"string" "string"
number
boolean
table
table (integer keys)
"null"
object
thread
userdata

Parameters

value

Lua value to be encoded.

Return value

Returns the encoded JSON string or a nil value in case of error.

Example

-- use the json binary module -- must be in the same folder as this Lua script -- or in the 'modules' folder of your LuaRT installation path local json = require "json" -- Lua array (integer only indexed table) local array = { 1, 2, 3, "Hello !" } -- prints the JSON representation of the array value -- should output [1,2,3,"Hello !"] print(json.encode(array))