JSON

json.object

Marks a table as a JSON object so encoding keeps object semantics.

Syntax

json.object(source: table): table

Arguments

NameTypeDescription
sourcetableSource value used by the operation.

Returns

NameTypeDescription
objecttableCreated drawing object.

Description

Marks a table as a JSON object so encoding keeps object semantics.

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

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

Example

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

local profile = json.object({
    name = "Guest",
    active = true,
})
local empty = json.object()

print(json.encode(profile))
print(json.encode(empty))