Syntax
json.pretty(value: any, options?: EncodeOptions): stringArguments
| Name | Type | Description |
|---|---|---|
value | any | New value to write. |
options? | EncodeOptions | Optional settings table that controls how the operation behaves. |
Returns
| Name | Type | Description |
|---|---|---|
json | string | JSON string result. |
Description
Alias-style helper that serializes a value as formatted JSON.
Call it with 2 parameter(s): value, options. The argument table explains which values are required and which ones only refine the behavior.
It returns json (string). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Pretty-print a Luau value using the encodePretty-compatible alias.
local text = json.pretty({
category = "JSON",
functions = 24,
})
print(text)Types
EncodeOptions
Controls JSON serialization and formatting.
pretty? boolean Enables formatted, multi-line JSON output.sortKeys? boolean Sorts object keys before encoding.emptyTableAsArray? boolean Encodes an empty table as an array instead of an object.errorOnUnsupported? boolean Raises an error instead of substituting unsupported values.encodeInvalidNumbersAsNull? boolean Encodes NaN and infinite numbers as JSON null.maxDepth? integer Sets the maximum nesting depth, clamped from 1 to 4096.indent? string Sets the indentation string, limited to 32 characters.