Module:Lua json: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
         local jsonData = mw.text.jsonDecode(content)
         local jsonData = mw.text.jsonDecode(content)
         if jsonData and jsonData.schemas and jsonData.schemas.Project then
         if jsonData and jsonData.schemas and jsonData.schemas.Project then
             return jsonData.schemas.Project.title
             return jsonData.schemas.Project.description
         else
         else
             return "Error: Invalid JSON structure"
             return "Error: Invalid JSON structure"

Revision as of 15:52, 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.description
        else
            return "Error: Invalid JSON structure"
        end
    else
        return "Error: JSON page does not exist"
    end
end

return p