Module:Json

--

-- A simple wrapper around @{mw.text.jsonEncode}. -- -- @module json -- @release	stable -- @author User:ExE Boss -- @require Module:Arguments -- @see    @{mw.text.jsonEncode}

local getArgs = require("Module:Arguments").getArgs; local json = {};

-- Encodes a value to JSON, also supports invocation -- -- @param {Frame|table|string|number|boolean|nil} value -- @return {string}

function json.encode(value) if (		type(value) == "table"		and type(value.args) == "table"		and type(value.getParent) == "function"	) then local args = getArgs(value); value = args[1];

local success, result = pcall(mw.text.jsonEncode, value); if (success) then return result; else return ' ' .. result .. " ";		end else return mw.text.jsonEncode(value); end end

return json;