json.minify Synchronous

Parse JSON and write it back without optional formatting whitespace. Use it when you want a compact stored or transmitted representation of an existing document.

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

Parameters

Function parameters
ParameterTypeDescription
textstringJSON document to compact.
optionsJsonDecodeOptions?Optional useNull boolean or options table. By default null becomes json.null and maxDepth is 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 JSON raises a parse error.

Usage notes

This rebuilds the document; it does not simply delete whitespace characters from the original string. Whitespace inside string values remains data.

Example

Example
Luau
local formatted = [[{ "message": "hello world", "count": 2 }]]
print(json.minify(formatted))
Kawaii documentation