JSON API documentation

Manipulation of JSON data strings.

FUNCTION
json.decode()

decode JSON from a string to a lua-table

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

RETURNS

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,
    }
  }
}