Skip to content

json⚓︎

Provides support for interacting with json data through an extended dkjson module.

Properties⚓︎

json.null⚓︎

You can use this value for setting explicit null values.

Returns:

  • result (number)

json.version⚓︎

Current version of dkjson.

Returns:

  • result (string)

Functions⚓︎

json.decode⚓︎

Decode string into a table.

json does not support mixed string and number indices

If the encoded table had any string indices, then the table returned by this function will have no number indices. For example, [1] could have been converted to ["1"] in the encoding process.

local result = json.decode(s, position, nullValue)

Parameters:

  • s (string)
  • position (number): Default: 1.
  • nullValue (string, nil): Default: nil.

Returns:

  • result (table)

json.encode⚓︎

Create a string representing the object. Object can be a table, string, number, boolean, nil, json.null, or any object with a __tojson function in its metatable. A table can only use strings and numbers as keys, and its values have to be valid objects as well. This function will raise an error if called on an invalid data type or on a data structure that contains reference cycles.

json does not support mixed string and number indices

If the encoded table has any string indices, then this function will convert all number indices to string indices. For example, [1] could be converted to ["1"]. This should be taken into account when loading/decoding json files.

local result = json.encode(object, state)

Parameters:

  • object (table)
  • state (table?)

Returns:

  • result (string)

json.loadfile⚓︎

Loads the contents of a file through json.decode. Files loaded from "Data Files\MWSE\{fileName}.json".

json does not support mixed string and number indices

If the encoded table had any string indices, then the table returned by this function will have no number indices. For example, [1] could have been converted to ["1"] in the encoding process. If you're using this to load a configuration file for your mod, it's recommended you use mwse.loadConfig instead.

local result = json.loadfile(fileName)

Parameters:

  • fileName (string)

Returns:

  • result (table)

json.quotestring⚓︎

Quote a UTF-8 string and escape critical characters using JSON escape sequences. This function is only necessary when you build your own __tojson functions.

local result = json.quotestring(s)

Parameters:

  • s (string)

Returns:

  • result (string)

json.savefile⚓︎

Saves a serializable table to Data Files\MWSE\{fileName}.json, using json.encode.

json.savefile(fileName, object, config)

Parameters:

  • fileName (string)
  • object (table)
  • config (table): Optional.