JSON parser and serializer
json.decode_invalid_numbers(setting)
json.parse()may generate an error when trying to decode numbers not supported by the JSON specification. Invalid numbers are defined as: infinity, not-a-number (NaN) and hexadecimal.
json.decode_max_depth(depth)
json.parse()will generate an error when parsing deeply nested JSON once the maximum array/object depth has been exceeded. This check prevents unnecessarily complicated JSON from slowing down the application, or crashing the application due to lack of process stack space.
json.encode_invalid_numbers(setting)
json.stringify()may generate an error when encoding floating point numbers not supported by the JSON specification such as Infinity and NaN. This behavior can be changed by calling this function.
json.encode_max_depth(depth)
json.stringify()will generate an error when encoding deeply nested JSON once the maximum table depth has been exceeded. This check prevents unnecessarily complicated JSON from slowing down the application, or crashing the application due to lack of process stack space.
json.encode_number_precision(precision)
The amount of significant digits returned by
json.stringify()when encoding numbers can be changed to balance accuracy versus performance. For data structures containing many numbers, setting json.encode_number_precision to a smaller integer, for example 3, can improve encoding performance by up to 50%. By default, Lua CJSON will output 14 significant digits when converting a number to text.
json.encode_sparse_array()
json.stringify()classifies a Lua table into one of three kinds when encoding a JSON array. This is determined by the number of values missing from the Lua array as follows:
json.parse(json_text)
Parses a UTF-8 JSON string into a Lua object (table, number, string, etc).
json.stringify(object)
Serializes a Lua object into a JSON string. It supports the following types:
boolean,nil,number,string,table