JSON

json.minify

Parse JSON string แล้ว re-encode ด้วย Real default non-pretty JSON encoder output.

ไวยากรณ์

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

Arguments

ชื่อชนิดคำอธิบาย
jsonstringJSON string ที่ถูก parse ก่อน minifying. function อ่าน argument นี้ด้วย string type checking.
options?DecodeOptionsOptional decode options ที่ใช้ระหว่าง parsing input JSON. boolean ตั้งค่า useNull. table ตั้งค่า useNull และ maxDepth ได้.

Returns

ชื่อชนิดคำอธิบาย
minifiedstringJSON string ที่สร้างหลัง parsing และ re-encoding input ด้วย default encode options.

คำอธิบาย

Parse JSON string แล้ว re-encode ด้วย Real default non-pretty JSON encoder output.

เรียกด้วย parameter 2 ค่า: json, options ตาราง arguments อธิบายค่าที่จำเป็นและค่าที่ปรับพฤติกรรม

ส่งคืน minified (string) ใช้ตาราง returns เพื่อแยกค่าที่สำเร็จ ผลลัพธ์ nil และ error ที่จัดการต่อได้

ตัวอย่าง

Parse valid JSON แล้ว re-encode ด้วย default compact JSON output.

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

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

Types

DecodeOptions

ควบคุมพฤติกรรมการแยกวิเคราะห์ JSON

useNull? boolean แสดงถึง JSON null ด้วย null sentinel ของไลบรารีแทนที่จะเป็น nilmaxDepth? integer ตั้งค่าความลึกของการซ้อนสูงสุด โดยยึดไว้ตั้งแต่ 1 ถึง 4096