jsonConfig⚓︎
A table used to configure the behavior of functions in the json API.
Properties⚓︎
buffer
⚓︎
Used to store the strings for the result so they can be concatenated at once. When it isn't given, the encode function will create it temporarily and will return the concatenated result.
Info
This field is used internally by the implementation and is usually not of interest to the end user.
Returns:
result
(string[], nil)
bufferlen
⚓︎
When bufferlen is set, it has to be the index of the last element of buffer.
Info
This field is used internally by the implementation and is usually not of interest to the end user.
Returns:
result
(integer, nil)
exception
⚓︎
When exception is raised, this callback function will be called whenever the encoder cannot encode a given value. The parameters are reason
, value
, state
and defaultmessage
. reason
is either "reference cycle"
, "custom encoder failed"
or "unsupported type"
. value
is the original value that caused the exception, state
is this jsonConfig
table, defaultmessage
is the message of the error that would usually be raised. The callback can either return true
and write encoded value
directly to the buffer
or you can return the encoded string. If the callback decides to raise an error, return nil
and the desired error message. An example implementation for an exception function is given in json.encodeexception
.
Returns:
result
((fun(reason: "reference cycle", "custom encoder failed", "unsupported type", value, state: jsonConfig, defaultMessage: string): string, true, nil, string?)?)
indent
⚓︎
When indent is set, the created string will contain newlines and indentations. Otherwise it will be one long line.
Returns:
result
(boolean, nil)
keyorder
⚓︎
Used to specify the ordering of keys in the encoded output. If an object has keys which are not in this array they are written after the sorted keys.
Returns:
result
(string[], nil)
level
⚓︎
This is the initial level of indentation used when indent is set. For each level two spaces are added. When absent it is set to 0.
Info
This field is used internally by the implementation and is usually not of interest to the end user.
Returns:
result
(integer, nil)
tables
⚓︎
This field is used to detect cyclic references. It is created temporarily when absent. Every table that is currently processed is used as key, the value is true.
Info
This field is used internally by the implementation and is usually not of interest to the end user.
Returns:
result
(table<table, true>, nil)