JSON_EMPTY_ARRAY
JSON_EMPTY_ARRAY is a global sentinel value that serializes as [] in JSON output. Use it when you need an empty array instead of the default empty object {}.
Assign JSON_EMPTY_ARRAY to any table key to force an empty JSON array:
-- Without sentinel: empty table becomes {}json_encode({ items = {} }) -- '{"items":{}}'
-- With sentinel: force empty arrayjson_encode({ items = JSON_EMPTY_ARRAY }) -- '{"items":[]}'Server responses
Section titled “Server responses”get.data = function(self) return { status = 200, body = { items = JSON_EMPTY_ARRAY, meta = {} -- this stays as {} }, }endWith array parameter
Section titled “With array parameter”The array parameter on json_encode works independently. JSON_EMPTY_ARRAY always produces [] regardless of the flag:
json_encode(JSON_EMPTY_ARRAY) -- "[]"json_encode(JSON_EMPTY_ARRAY, false) -- "[]"json_encode(JSON_EMPTY_ARRAY, true) -- "[]"See Also
Section titled “See Also”- json_encode - Encode Lua value to JSON string
- json_decode - Decode JSON string to Lua value