JSON

Manipulation of JSON data strings.

json.decode()

decode JSON from a string to a lua-table

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

PARAMETERS

json -

string json data

RETURN

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