Module:Lua json: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
local p = {}
local p = {}


function p.getProjectData()
function p.getDataByTitle(titleParam, titleValue, targetParam)
     local jsonPage = mw.title.new("Data:Project/41")
     local pages = mw.site.indexPages("Data:")
     if jsonPage and jsonPage.exists then
     local results = {}
        local content = jsonPage:getContent()
 
        local jsonData = mw.text.jsonDecode(content)
    for _, page in ipairs(pages) do
        if jsonData and jsonData.schemas and jsonData.schemas.Project then
        local jsonPage = mw.title.new(page)
            return jsonData.schemas.Project.objective
        if jsonPage and jsonPage.exists then
        else
            local content = jsonPage:getContent()
             return "Error: Invalid JSON structure"
            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
    else
        return "Error: JSON page does not exist"
     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