lljson.decode (json: string) -> string|number|vector|uuid|quaternion|boolean|{}|nildecode json string to lua value
lljson.decode will error if an invalid string is passed to it.
It is recommended to use
pcall or
xpcall to wrap the
method and handle the resulting error
pcalllocal valid_json = '["first","second","third"]'
local ok, result = pcall(lljson.decode, valid_json)
if ok then
ll.OwnerSay(`The json was valid. '{result[1]}' '{result[3]}'`) -- prints: The json was valid. 'first' 'third'
else
ll.OwnerSay("The json was invalid") -- will not be called
end
local invalid_json = '"first","second","third"'
local ok, result = pcall(lljson.decode, invalid_json)
if ok then
ll.OwnerSay(`The json was valid. '{result[1]}' '{result[3]}'`) -- will not be called
else
ll.OwnerSay("The json was invalid") -- prints: The json was invalid
end
pcalllocal valid_json = '["first","second","third"]'
local result = lljson.decode(valid_json)
ll.OwnerSay(`The json was valid. '{result[1]}' '{result[3]}'`) -- prints: The json was valid. 'first' 'third'
local invalid_json = '"first","second","third"'
local result = lljson.decode(invalid_json) -- Script errors and dies
ll.OwnerSay(`The json was valid. '{result[1]}' '{result[3]}'`) -- will not be called
{
"def": "func",
"name": "decode",
"energy": 0,
"must_use": true,
"sleep": 0,
"signatures": [
{
"def": "signature",
"result": [
{
"name": "",
"def": "result",
"desc": "",
"variadic": false,
"type": [
{
"def": "simple",
"value": "string"
},
{
"def": "simple",
"value": "number"
},
{
"def": "simple",
"value": "vector"
},
{
"def": "simple",
"value": "uuid"
},
{
"def": "simple",
"value": "quaternion"
},
{
"def": "simple",
"value": "boolean"
},
{
"def": "simple",
"value": "{}"
},
{
"def": "simple",
"value": "nil"
}
],
"optional": false
}
],
"args": [
{
"def": "arg",
"name": "json",
"desc": "json string to decode",
"type": [
{
"def": "simple",
"value": "string"
}
],
"variadic": false,
"optional": false
}
]
}
],
"desc": "decode json string to lua value",
"link": "",
"takesSelf": false,
"private": false
}