Module:Process entire Ask query with format json: Difference between revisions
Jump to navigation
Jump to search
Created page with "local p = {} function p.processData(frame) local jsonString = frame.args.data local dataTable = mw.text.jsonDecode(jsonString) -- Now you can work with dataTable in Lua -- For example, iterate through the results: --local output = "" --for _, item in ipairs(dataTable.results) do -- output = output .. "City: " .. item.printouts.Population[1].fulltext .. ", Area: " .. item.printouts.Area[1].fulltext .. "\n" local vartype1 = type(jsonSt..." |
No edit summary |
||
| Line 3: | Line 3: | ||
function p.processData(frame) | function p.processData(frame) | ||
local jsonString = frame.args.data | local jsonString = frame.args.data | ||
local dataTable = mw.text.jsonDecode(jsonString) | --local dataTable = mw.text.jsonDecode(jsonString) | ||
-- Now you can work with dataTable in Lua | -- Now you can work with dataTable in Lua | ||
| Line 12: | Line 12: | ||
local vartype1 = type(jsonString) | local vartype1 = type(jsonString) | ||
local vartype2 = type(dataTable) | --local vartype2 = type(dataTable) | ||
return "jsonString is type " .. vartype1 .. "; dataTable is type " .. vartype2 .. "." | return "jsonString is type " .. vartype1 .. ";" -- dataTable is type " .. vartype2 .. "." | ||
Revision as of 11:33, 28 November 2025
Documentation for this module may be created at Module:Process entire Ask query with format json/doc
local p = {}
function p.processData(frame)
local jsonString = frame.args.data
--local dataTable = mw.text.jsonDecode(jsonString)
-- Now you can work with dataTable in Lua
-- For example, iterate through the results:
--local output = ""
--for _, item in ipairs(dataTable.results) do
-- output = output .. "City: " .. item.printouts.Population[1].fulltext .. ", Area: " .. item.printouts.Area[1].fulltext .. "\n"
local vartype1 = type(jsonString)
--local vartype2 = type(dataTable)
return "jsonString is type " .. vartype1 .. ";" -- dataTable is type " .. vartype2 .. "."
end
return p