json.minify Synchronous

Parse JSON text and serialize it again without optional whitespace. Use it to remove formatting from JSON before storing or transferring it. String contents are preserved; only the serialized representation is rebuilt.

Syntax
Luau
json.minify(text: string, options: JsonDecodeOptions?) -> string

Parameters

Function parameters
ParameterTypeDescription
textstringJSON document to compact.
optionsJsonDecodeOptions?Optional boolean useNull flag or options table. Null preservation is enabled by default; maxDepth defaults to 256.

Argument fields

JsonDecodeOptions fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}
FieldDescription
useNullDefaults to true, preserving JSON null as json.null. false converts null to nil, which can remove table entries. A boolean options argument is shorthand for this field.
maxDepthMaximum nesting depth. Defaults to 256; an integer is required and is clamped to 1–4096.

Returns

string

Compact JSON text. Invalid input raises a parse error.

Example

Example
Luau
local pretty = json.encodePretty({ colors = { "pink", "white" } })
print(json.minify(pretty)) -- {"colors":["pink","white"]}
Kawaii documentation