Homepage
Games
News
News βΎ
All
Transfers
Drama
Business
Sponsors
Mergers
Investors
Hires
Companies
More
People
Tournaments
Brands
Brands βΎ
Companies
Organizations
Sponsors
Other
Locations
Search
Editing
Module:Json
From TwogPedia
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local Json = {} local Arguments = require('Module:Arguments') function Json.fromArgs(frame) local args = Arguments.getArgs(frame) mw.log(args) return Json.stringify(args) end function Json.stringify(obj, pretty) return mw.text.jsonEncode(obj, pretty == true and mw.text.JSON_PRETTY or nil) end function Json.parse(obj) local parse = function(object) return mw.text.jsonDecode(object, mw.text.JSON_TRY_FIXING) end local status, res = pcall(parse, obj); if status then return res, false else mw.log('Error: could not parse Json:') mw.logObject(obj) mw.log(debug.traceback()) return {}, true end end function Json.parseIfString(obj) if type(obj) == 'string' then return Json.parse(obj) else return obj end end --[[ Attempts to parse a JSON encoded table. Returns nil if unsuccessful. Example: JsonExt.parseIfTable('{"a" = 3}') -- Returns {a = 3} ]] function Json.parseIfTable(any) if type(any) == 'string' then local firstChar = any:sub(1, 1) if firstChar == '{' or firstChar == '[' then local result, hasError = Json.parse(any) if not hasError then return result end end end return nil end return Json
Summary:
Please note that all contributions to TwogPedia may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TwogPedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Preview page with this template
Template used on this page:
Module:Json/doc
(
edit
)
No categories
Edit