JSON

JSON is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

JSON allows you to encode Lua table as JSON string and decode JSON string as Lua table.

Functions

table Decode ( string encodedString )

Takes a string as parameter and returns a Lua table.

local jsonstring = "{\"body\":\"A message.\",\"status_code\":200}"
local data = JSON:Decode(jsonstring)
print(data.status_code, data.body)
-- prints "200.0 A message."

Takes a Lua table as parameter and returns an encoded string.
This function handles basic types (number, string, boolean, tables) and skip functions.

local playerInfo = {}
playerInfo.hp = 100
playerInfo.name = "Bob"
local encoded = JSON:Encode(playerInfo)
print(encoded)
-- prints the string {"hp":100,"name":"Bob"}