Module:GetJSON: Difference between revisions

From AlternateWiki
no edit summary
No edit summary
No edit summary
Tag: Reverted
(One intermediate revision by the same user not shown)
Line 7:
local m = {}
-- Load JSON data from the first argument passed to the module
m.rootif = mw.loadJsonData(frame.args[1]) == "yes" then
m.root = mw.text.jsonDecode(frame.args[1])
else
m.root = mw.loadJsonData(frame.args[1])
end
-- Function to split a key string by "."
local function splitKey(key)
Line 77 ⟶ 81:
 
-- Split the key provided in the second argument
local keys = splitKey(frame.args[23])
-- Get the value from the nested table using the keys
local value = getValueByKeys(m.root, keys)
Line 86 ⟶ 90:
if type(value) == "table" then
-- If the fourth parameter is "keys"
if frame.args[45] == "keys" then
-- Return keys of the table
local str = ""
Line 105 ⟶ 109:
else
-- If the third argument is not nil, return it
if frame.args[34] ~= nil then
return frame.args[34]
else
return "" -- Return an empty string if no value is found
Cookies help us deliver our services. By using our services, you agree to our use of cookies.