You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to the documentation, the ngx.say function expects a array table (with numeric index) as a parameter and not a table with string-type indexes.
[error] 1265#1265: *64 lua entry thread aborted: runtime error: content_by_lua(default.conf:17):3: bad argument #1 to 'say' (non-array table found)
stack traceback:
coroutine 0:
[C]: in function 'say'
Non-array table arguments will cause a Lua exception to be thrown.
Activity
guysv commentedon May 31, 2020
I'd guess that json.lua is not in nginx's (maybe special)
$LUA_PATH?edenisn commentedon May 31, 2020
ahhh, it's present in nginx.conf:
lua_package_path "/usr/local/lib/lua/?.lua;;";edenisn commentedon May 31, 2020
If it's possible, can you pls provide example with NGINX? Thanks @guysv
edenisn commentedon May 31, 2020
One more very strange thing: if I use code below in nginx.conf:
location /test { content_by_lua_block { local json = require("json") ngx.say(json.encode({ 1, 2, 3, { x = 10 } })) } }It works fine
[1,2,3,{"x":10}]xphip commentedon Jun 28, 2022
Isn't a lib related issue but a third-party module limitation (
openresty/lua-nginx-module).https://github.com/openresty/lua-nginx-module/blob/.../src/ngx_http_lua_output.c#L285
According to the documentation, the ngx.say function expects a array table (with numeric index) as a parameter and not a table with string-type indexes.
https://github.com/openresty/lua-nginx-module#ngxprint:~:text=Non%2Darray%20table...
A possible solution would be to use the lib itself to encode to string:
Tests: