Module:GetJSON: Difference between revisions
From AlternateWiki
no edit summary
No edit summary |
No edit summary Tag: Reverted |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7:
local m = {}
-- Load JSON data from the first argument passed to the module
m.root = mw.text.jsonDecode(frame.args[2])
else
m.root = mw.loadJsonData(frame.args[2])
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[
-- 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[
-- Return keys of the table
local str = ""
Line 105 ⟶ 109:
else
-- If the third argument is not nil, return it
if frame.args[
return frame.args[
else
return "" -- Return an empty string if no value is found
|