JSON

json.array

Creates a new table marked as a JSON array for json.encode, copying the 1.#source sequence when a source table is provided.

Syntax

json.array(source?: table): table

Arguments

NameTypeDescription
source?tableOptional source table. When omitted or nil, json.array returns a new empty array-marked table. When provided, only numeric sequence entries from 1 with #source are copied into the new table.

Returns

NameTypeDescription
arraytableNew table with the JSON array marker. json.encode serializes it as a JSON array; the original source table is not returned.

Description

Creates a new table marked as a JSON array for json.encode, copying the 1.#source sequence when a source table is provided.

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

Create an array-marked copy so json.encode serializes the value as a JSON array.

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

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