diff --git a/internal/core/plugins/api_utils.go b/internal/core/plugins/api_utils.go index 93531fe..e002b0d 100644 --- a/internal/core/plugins/api_utils.go +++ b/internal/core/plugins/api_utils.go @@ -81,6 +81,16 @@ func luaValueToGo(v lua.LValue) interface{} { } return arr } + // Check if table has any keys at all — empty tables are ambiguous. + // DB queries return empty tables when no rows match; the frontend + // expects a valid array [] (with .length), not {} (where .length is undefined). + hasKeys := false + val.ForEach(func(k lua.LValue, v lua.LValue) { + hasKeys = true + }) + if !hasKeys { + return make([]interface{}, 0) + } m := make(map[string]interface{}) val.ForEach(func(k lua.LValue, v lua.LValue) { m[fmt.Sprintf("%v", k)] = luaValueToGo(v)