json. array Synchronous
Copy the sequence portion of a table and mark the result for JSON array encoding. This is useful when an empty collection must serialize as []. Use the marker when a consumer expects a list even when it contains no items. Adding elements to the returned table keeps that intended representation.
Luau
json.array(source: Table?) -> TableParameters
| Parameter | Type | Description |
|---|---|---|
source | Table? | Optional table to copy from indices 1 through its length. Omit it to create an empty marked array. |
Returns
TableA new table carrying array metadata. Named keys are not copied; nested values are shared with the input.
Example
Luau
local items = json.array()
print(json.encode(items)) -- []
table.insert(items, "first")
print(json.encode(items)) -- ["first"]