- Select ref document -

JSON API documentation

version 1.2.143

Manipulation of JSON data strings.

Functions

json.decode

json.decode(json)

Decode a string of JSON data into a Lua table. A Lua error is raised for syntax errors.

Parameters

json

string json data

json

string json data

Returns

data

table decoded json

data

table decoded json

Examples

Converting a string containing JSON data into a Lua table:

function init(self)
    local jsonstring = '{"persons":[{"name":"John Doe"},{"name":"Darth Vader"}]}'
    local data = json.decode(jsonstring)
    pprint(data)
end

Results in the following printout:

{
  persons = {
    1 = {
      name = John Doe,
    }
    2 = {
      name = Darth Vader,
    }
  }
}