Module:Sandbox/Rockingerser/Json

local module = {}

function module:stringify(Table) local result = "" local array = false

for _, value in ipairs(Table) do		array = true if type(value) == "string" then value = "\"" .. value .. "\"" elseif value == nil then value = "null" elseif type(value) == "table" then value = self:stringify(value) end

result = result .. value .. ", "	end

if not array then for key, value in pairs(Table) do			if type(value) == "string" then value = "\"" .. value .. "\"" elseif value == nil then value = "null" elseif type(value) == "table" then value = self:stringify(value) end result = result .. string.format("%q: %s, ", key, tostring(value)) end end

if result:sub(-2) == ", " then result = result:sub(1,-3) end

if array then result = "[ " .. result .. " ]"	else result = "{ " .. result .. " }"	end mw.log(result) return result end

return module