JSON

Manipulation of JSON data strings.

json.decode(json, options)

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 - json data

options - table with decode options

RETURN

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


json.encode(tbl, options)

encode a lua table to a JSON string

Encode a lua table to a JSON string. A Lua error is raised for syntax errors.

PARAMETERS

tbl - lua table to encode

options - table with encode options

RETURN

json - encoded json

EXAMPLES

Convert a lua table to a JSON string:

function init(self)
     local tbl = {
          persons = {
               { name = "John Doe"},
               { name = "Darth Vader"}
          }
     }
     local jsonstring = json.encode(tbl)
     pprint(jsonstring)
end
Results in the following printout:
{"persons":[{"name":"John Doe"},{"name":"Darth Vader"}]}


json.null

null

Represents the null primitive from a json file