JSON

json.minify

Removes unnecessary whitespace from JSON while preserving its value.

Syntax

json.minify(json: string, options?: DecodeOptions): string

Arguments

NameTypeDescription
jsonstringJSON string to parse, format, minify, or validate.
options?DecodeOptionsOptional settings table that controls how the operation behaves.

Returns

NameTypeDescription
minifiedstringJSON string without unnecessary whitespace.

Description

Removes unnecessary whitespace from JSON while preserving its value.

Call it with 2 parameter(s): json, options. The argument table explains which values are required and which ones only refine the behavior.

It returns minified (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Remove unnecessary whitespace from valid JSON.

local formatted = [[{
    "name": "Real",
    "enabled": true
}]]

print(json.minify(formatted))

Types

DecodeOptions

Controls JSON parsing behavior.

useNull? boolean Represents JSON null with the library's null sentinel instead of nil.maxDepth? integer Sets the maximum nesting depth, clamped from 1 to 4096.