Module:Lua json: Difference between revisions
Jump to navigation
Jump to search
(Created page with "local p = {} function p.getProjectData() local data = mw.loadData("Data:Project/41") return data.schemas.Project.title end return p") |
No edit summary |
||
Line 2: | Line 2: | ||
function p.getProjectData() | function p.getProjectData() | ||
local | local jsonPage = mw.title.new("Data:Project/178") | ||
return | 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.title | |||
else | |||
return "Error: Invalid JSON structure" | |||
end | |||
else | |||
return "Error: JSON page does not exist" | |||
end | |||
end | end | ||
return p | return p |
Revision as of 15:48, 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/178")
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.title
else
return "Error: Invalid JSON structure"
end
else
return "Error: JSON page does not exist"
end
end
return p