pairs function - not getting the expected result

I make a request from a php page using http.request which returns the following json array:

{“1”:[“101”],“2”:[“102”],“3”:[“103”],“4”:[“104”]}  

If I understand correctly, a json array once decoded turns in to a table.

So all I am trying to do is print the values to the console. Here is the code

local response = http.request(URL)

local data = json.decode(response)

for k,v in pairs(data) do print(k,v) end

And this is what shows up on the console: 

    

1    table: 05C69778    

4    table: 05C69CA0    

3    table: 05C69AE8    

2    table: 05C69958    

I was expecting to see

1 101

2 102

3 103

4 104

What am I doing or not doing correctly to get the desired result?

Thanks

the way your json is setup it would decode like this

data = { {101},{102},{103},{104} }

so when you read data with pairs your getting each table. you either need to restructure the json file or have your code check the results and if it’s a table the do pairs on it also
try this
https://gist.github.com/hashmal/874792

yes, your json contains an “array of arrays”, that’s why printing one of the (outer) array elements yields “table <address>”. assuming the data is formatted correctly and it’s the code that needs to change, then probably what you want is:

for k,v in pairs(data) print(k,v[1]) end

Thanks to both of you for your advice and the link. Just adding the [1] did the trick. Now I get:

1    101    

4    104    

3    103    

2    102    

the way your json is setup it would decode like this

data = { {101},{102},{103},{104} }

so when you read data with pairs your getting each table. you either need to restructure the json file or have your code check the results and if it’s a table the do pairs on it also
try this
https://gist.github.com/hashmal/874792

yes, your json contains an “array of arrays”, that’s why printing one of the (outer) array elements yields “table <address>”. assuming the data is formatted correctly and it’s the code that needs to change, then probably what you want is:

for k,v in pairs(data) print(k,v[1]) end

Thanks to both of you for your advice and the link. Just adding the [1] did the trick. Now I get:

1    101    

4    104    

3    103    

2    102