Syntax
json.object(source?: table): tableArguments
| Name | Type | Description |
|---|---|---|
source? | table | Optional source table to copy into the new object table. If omitted or nil, an empty object table is returned. |
Returns
| Name | Type | Description |
|---|---|---|
object | table | New table marked with Real's JSON object marker. Source entries are copied, except Real's JSON type marker. |
Description
Creates a new table marked as a JSON object so Real's JSON encoder treats it as an object.
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
Create a new table marked as a JSON object, including an empty object.
local profile = json.object({
name = "Guest",
active = true,
})
local empty = json.object()
print(json.encode(profile))
print(json.encode(empty))