Module:JSON/sandbox

From MediaWiki.org
Jump to navigation Jump to search
Module documentation

This module exposes two functions:

encode( o )[edit]

Returns the table / string / boolean / number / nil / json.null value as a JSON-encoded string.

decode( json_string )[edit]

Returns a Lua object populated with the data encoded in the JSON string json_string.
-- For unit tests, see [[Module:Bananas/testcases]]
local json = require('Module:JSON')
local p = {}
local test = {}
 
function p.hello()
	test = json.decode('{\'Hello\':\'测试\'}');
 
	return test['Hello']
end
 
return p