Version: beta
FUNCTIONS | |
---|---|
json.decode() | decode JSON from a string to a lua-table |
json.encode() | encode a lua table to a JSON string |
CONSTANTS | |
---|---|
json.null | null |
json.decode(json,[options])
Decode a string of JSON data into a Lua table. A Lua error is raised for syntax errors.
PARAMETERS
json |
string |
json data |
[options] |
table |
table with decode options
|
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
{
persons = {
1 = {
name = John Doe,
}
2 = {
name = Darth Vader,
}
}
}
json.encode(tbl,[options])
Encode a lua table to a JSON string. A Lua error is raised for syntax errors.
PARAMETERS
tbl |
table |
lua table to encode |
[options] |
table |
table with encode options
|
RETURNS
json |
string | 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
{"persons":[{"name":"John Doe"},{"name":"Darth Vader"}]}
Represents the null primitive from a json file