Module:Lua json: Difference between revisions
Jump to navigation
Jump to search
No edit summary Tag: Reverted |
No edit summary Tag: Manual revert |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.getProjectData() | |||
function p. | local jsonPage = mw.title.new("Data:Project/41") | ||
local | if jsonPage and jsonPage.exists then | ||
local content = jsonPage:getContent() | |||
local jsonData = mw.text.jsonDecode(content) | |||
if | if jsonData and jsonData.schemas and jsonData.schemas.Project then | ||
local | return jsonData.schemas.Project.objective | ||
else | |||
return "Error: Invalid JSON structure" | |||
end | end | ||
else | else | ||
return "Error: JSON page does not exist" | |||
return "Error: | |||
end | end | ||
end | end | ||
return p | return p |
Revision as of 17:18, 16 March 2024
Documentation for this module may be created at Module:Lua json/doc
local p = {}
function p.getProjectData()
local jsonPage = mw.title.new("Data:Project/41")
if jsonPage and jsonPage.exists then
local content = jsonPage:getContent()
local jsonData = mw.text.jsonDecode(content)
if jsonData and jsonData.schemas and jsonData.schemas.Project then
return jsonData.schemas.Project.objective
else
return "Error: Invalid JSON structure"
end
else
return "Error: JSON page does not exist"
end
end
return p