Skip to main content

json

Description:

  JSON library for Dora.

decode

Type: Function.

Description:

  Parses the specified JSON text and returns the corresponding table.

Signature:

decode: function(json: string, maxDepth?: integer, allowcomments?: boolean): table | nil, nil | string

Parameters:

ParameterTypeDescription
jsonstringThe JSON text to parse.
maxDepthnumber[optional] The maximum depth of parsing (default is 128).
allowcommentsboolean[optional] Whether to allow comments in the JSON text (default is false).

Returns:

Return TypeDescription
table | nil, nil | stringThe table representing the JSON data, or nil with an error message if the JSON text cannot be parsed.

encode

Type: Function.

Description:

  Dumps the specified table into a JSON text.

Signature:

encode: function(tab: table, format?: boolean, empty_as_array?: boolean, num_as_str?: boolean, maxdepth?: integer): string | nil, nil | string

Parameters:

ParameterTypeDescription
tabtableThe table to dump.
formatboolean[optional] Whether to format the JSON text (default is false).
empty_as_arrayboolean[optional] Whether to convert empty tables to arrays (default is false).
num_as_strboolean[optional] Whether to convert numbers to strings (default is false).
maxdepthnumber[optional] The maximum depth of conversion (default is 128).

Returns:

Return TypeDescription
stringThe JSON text representing the table, or nil with an error message if the table cannot be dumped.

null

Type: Field.

Description:

  Represents a JSON null value.

Signature:

null: JsonNull