-
-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not working with NGNIX #27
Comments
I'd guess that json.lua is not in nginx's (maybe special) |
ahhh, it's present in nginx.conf:
|
If it's possible, can you pls provide example with NGINX? Thanks @guysv |
One more very strange thing: if I use code below in nginx.conf:
It works fine
|
Isn't a lib related issue but a third-party module limitation ( 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: content_by_lua_block {
local json = require("json")
local decoded = json.decode('[1,2,3,{"x":10}]')
local encoded = json.encode(decoded)
ngx.say(encoded)
} Tests: content_by_lua_block {
ngx.say({["test"] = "ok"}) -- error
}
--
content_by_lua_block {
ngx.say({1, 2, 3, {["test"] = "ok"}}) -- error
}
--
content_by_lua_block {
ngx.say({1, 2, 3}) -- works
}
--
content_by_lua_block {
ngx.say({1, 2, 3, {1, 2}}) -- works
}
--
content_by_lua_block {
ngx.say({1, 2, 3, {[1] = "ok"}}) -- works
} |
I installed nginx-full and trying to use json.lua with NGINX:
Example:
nginx.conf:
location /test { default_type 'text/plain'; content_by_lua_block { local json = require("json") ngx.say(json.decode('[1,2,3,{"x":10}]')) }
then curl http://localhost:8080/test and got 500 error. But everything is ok in lua console:
`> json = require("json")
What I am doing wrong?
The text was updated successfully, but these errors were encountered: