JSON

json.array

Marks a table as a JSON array so encoding keeps array semantics, including for empty tables.

Syntax

json.array(source: table): table

Arguments

NameTypeDescription
sourcetableSource value used by the operation.

Returns

NameTypeDescription
arraytableTable marked for JSON array encoding.

Description

Marks a table as a JSON array so encoding keeps array semantics, including for empty tables.

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

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

Example

Mark a table as a JSON array, including when it is empty.

local tags = json.array({ "api", "docs", "luau" })
local empty = json.array()

print(json.encode(tags))
print(json.encode(empty))