json.object Synchronous

Mark a shallow copy of a table as a JSON object. This keeps an empty settings record as {} and makes the intended shape clear to a consumer.

Syntax
Luau
json.object(source: Table?) -> Table

Parameters

Function parameters
ParameterTypeDescription
sourceTable?Optional table to copy. Omit it to create an empty marked object.

Returns

Table

A new marked object table. Nested tables and other values are shared with the source.

Usage notes

The marker controls JSON shape; it does not validate that every copied key is suitable for JSON.

Example

Example
Luau
local settings = json.object()
print(json.encode(settings)) -- {}
settings.theme = "dark"
print(json.encode(settings)) -- {"theme":"dark"}
Kawaii documentation