It seems like this should be a simple thing. I have converted the following json structure to a lua table but I am having trouble trying to access the values inside of the array. I have looked through many questions and the internet in general and none of the examples I have tried work.
Here is the json that was converted to a lua table using cjson.decode
[{
"user": "user_1",
"password": "something",
"id": "35",
"message": "message 1"
},
{
"user": "user_2",
"password": "something",
"id": "5c",
"message": "message 2"
},
{
"user": "user_3",
"password": "something",
"id": "7e",
"message": "message 3"
},
{
"user": "user_3",
"password": "something",
"id": "6f",
"message": "message 4"
}]
I then try to access the variable like this:
ngx.say(users[0]["user"]);
However that does not work. I want to iterate the array and get out the user, password, id, and message at each index of the array but first I wanted to just see how to access the value of user at index 0 .. which should be user_1. I know this is a n00b question but any help would be greatly appreciated.