Module:GetJSON: Difference between revisions
From AlternateWiki
Content added Content deleted
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 7: | Line 7: | ||
local m = {} |
local m = {} |
||
-- Load JSON data from the first argument passed to the module |
-- Load JSON data from the first argument passed to the module |
||
if |
if frame.args[1] == "yes" then |
||
m.root = mw.text.jsonDecode(frame.args[1]) |
m.root = mw.text.jsonDecode(frame.args[1]) |
||
else |
else |
||
Line 81: | Line 81: | ||
-- Split the key provided in the second argument |
-- Split the key provided in the second argument |
||
local keys = splitKey(frame.args[ |
local keys = splitKey(frame.args[3]) |
||
-- Get the value from the nested table using the keys |
-- Get the value from the nested table using the keys |
||
local value = getValueByKeys(m.root, keys) |
local value = getValueByKeys(m.root, keys) |
||
Line 90: | Line 90: | ||
if type(value) == "table" then |
if type(value) == "table" then |
||
-- If the fourth parameter is "keys" |
-- If the fourth parameter is "keys" |
||
if frame.args[ |
if frame.args[5] == "keys" then |
||
-- Return keys of the table |
-- Return keys of the table |
||
local str = "" |
local str = "" |
||
Line 109: | Line 109: | ||
else |
else |
||
-- If the third argument is not nil, return it |
-- If the third argument is not nil, return it |
||
if frame.args[ |
if frame.args[4] ~= nil then |
||
return frame.args[ |
return frame.args[4] |
||
else |
else |
||
return "" -- Return an empty string if no value is found |
return "" -- Return an empty string if no value is found |