Module:Json parameter test: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
Tag: Manual revert
Line 17: Line 17:
      
      
-- JSON-Daten in Lua-Tabelle umwandeln
-- JSON-Daten in Lua-Tabelle umwandeln
     -- local json = mw.text.jsonDecode(jsonData)
     local json = mw.text.jsonDecode(jsonData)


     local result = {}
     local result = {}


     for _, item in ipairs(jsonData) do
     for _, item in ipairs(json) do
         local title = item.data.title
         local title = item.data.title
         local classNames = item.data["class names"]
         local classNames = item.data["class names"]

Revision as of 06:36, 27 May 2024

Documentation for this module may be created at Module:Json parameter test/doc

local p = {}

function p.generateClassLists(frame)
    -- JSON-Daten in einem Lua-String
    -- local jsonData = frame.args.jsonData
    
    -- {{#visualdataquery:[[unique title::+]]
	--   |?articleid
	--   |schema = Data classes
	--   |format = json-raw
	-- }}

    local jsonData = frame:callParserFunction( '#visualdataquery:[[unique title::+]]', { '?articleid', schema = 'Data classes', format = 'json-raw' } )

    -- Debugging: Gib die empfangenen JSON-Daten aus
    -- return "Received JSON Data: " .. tostring(jsonData)
    
	-- JSON-Daten in Lua-Tabelle umwandeln
    local json = mw.text.jsonDecode(jsonData)

    local result = {}

    for _, item in ipairs(json) do
        local title = item.data.title
        local classNames = item.data["class names"]
        table.insert(result, "== " .. title .. " ==")
        table.insert(result, "* " .. table.concat(classNames, "\n* "))
    end

    return table.concat(result, "\n\n")
end

return p