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.
Luau
json.minify(text: string, options: JsonDecodeOptions?) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
text | string | JSON document to compact. |
options | JsonDecodeOptions? | Optional useNull boolean or options table. By default null becomes json.null and maxDepth is 256. |
Argument fields
Luau
JsonDecodeOptions = boolean | {useNull: boolean?, maxDepth: number?}| Field | Description |
|---|---|
useNull | Defaults 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. |
maxDepth | Maximum nesting depth. Defaults to 256; an integer is required and is clamped to 1–4096. |
Returns
stringCompact 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
Luau
local formatted = [[{ "message": "hello world", "count": 2 }]]
print(json.minify(formatted))