JSON

json.type

Returns a string type name for a value.

Syntax

json.type(value: any): string

Arguments

NameTypeDescription
valueanyValue to classify. Passing no value returns the runtime type name for a missing stack value.

Returns

NameTypeDescription
jsonTypestringType name string. Verified JSON-specific returns are "null", "array", and "object". Non-table, non-json.null values use Lua type name, such as "nil", "boolean", "number", "integer", "string", "function", "object", "thread", "buffer", "class", "object", "vector", or "no value" depending on the runtime value.

Description

Returns a string type name for a value. json.null returns "null". Tables return "array" or "object" using the same table classification as json.isArray and json.isObject. Other values return the runtime Lua type name result.

Call it with 1 parameter(s): value. The argument table explains which values are required and which ones only refine the behavior.

It returns jsonType (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Check the exact type string returned by the JSON helper.

print(json.type(json.array({ "red", "blue" })))
print(json.type(json.object({ enabled = true })))
print(json.type(json.null))
print(json.type(nil))
print(json.type())