JSON

json.minify

Parses a JSON string and re-encodes it with Real's default non-pretty JSON encoder output.

Syntax

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

Arguments

NameTypeDescription
jsonstringJSON string to parse before minifying. The function reads this argument with string type checking.
options?DecodeOptionsOptional decode options used while parsing the input JSON. A boolean sets useNull. A table can set useNull and maxDepth.

Returns

NameTypeDescription
minifiedstringJSON string produced after parsing and re-encoding the input with default encode options.

Description

Parses a JSON string and re-encodes it with Real's default non-pretty JSON encoder output.

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

Parse valid JSON and re-encode it with default compact JSON output.

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

print(json.minify(formatted, {
    useNull = true,
}))

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.