Module:Lua json: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p. | function p.getDataByTitle(titleParam, titleValue, targetParam) | ||
local | local pages = mw.site.indexPages("Data:") | ||
if jsonPage and jsonPage.exists then | local results = {} | ||
for _, page in ipairs(pages) do | |||
local jsonPage = mw.title.new(page) | |||
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 and jsonData.schemas.Project[titleParam] == titleValue then | |||
table.insert(results, jsonData.schemas.Project[targetParam]) | |||
end | |||
end | end | ||
end | end | ||
return results | |||
end | end | ||
return p | return p |
Revision as of 16:03, 16 March 2024
Documentation for this module may be created at Module:Lua json/doc
local p = {}
function p.getDataByTitle(titleParam, titleValue, targetParam)
local pages = mw.site.indexPages("Data:")
local results = {}
for _, page in ipairs(pages) do
local jsonPage = mw.title.new(page)
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 and jsonData.schemas.Project[titleParam] == titleValue then
table.insert(results, jsonData.schemas.Project[targetParam])
end
end
end
return results
end
return p