Module:Lua json

From Visual Data Wiki
Jump to navigation Jump to search

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